1 |
dpavlin |
2 |
package Search::Estraier; |
2 |
|
|
|
3 |
|
|
use 5.008; |
4 |
|
|
use strict; |
5 |
|
|
use warnings; |
6 |
|
|
|
7 |
|
|
require Exporter; |
8 |
|
|
|
9 |
|
|
our @ISA = qw(Exporter); |
10 |
|
|
|
11 |
|
|
our %EXPORT_TAGS = ( 'all' => [ qw( |
12 |
|
|
) ] ); |
13 |
|
|
|
14 |
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
15 |
|
|
|
16 |
|
|
our @EXPORT = qw( |
17 |
|
|
); |
18 |
|
|
|
19 |
|
|
our $VERSION = '0.00'; |
20 |
|
|
|
21 |
|
|
use Carp; |
22 |
|
|
|
23 |
|
|
=head1 NAME |
24 |
|
|
|
25 |
|
|
Search::Estraier - pure perl module to use Hyper Estraier search engine |
26 |
|
|
|
27 |
|
|
=head1 SYNOPSIS |
28 |
|
|
|
29 |
|
|
use Search::Estraier; |
30 |
|
|
my $est = new Search::Estraier(); |
31 |
|
|
|
32 |
|
|
=head1 DESCRIPTION |
33 |
|
|
|
34 |
|
|
This module is implementation of node API of Hyper Estraier. Since it's |
35 |
|
|
perl-only module with dependencies only on standard perl modules, it will |
36 |
|
|
run on all platforms on which perl runs. It doesn't require compilation |
37 |
|
|
or Hyper Estraier development files on target machine. |
38 |
|
|
|
39 |
|
|
It is implemented as multiple packages which closly resamble Ruby |
40 |
|
|
implementation. It also includes methods to manage nodes. |
41 |
|
|
|
42 |
|
|
=cut |
43 |
|
|
|
44 |
|
|
package Search::Estraier::Document; |
45 |
|
|
|
46 |
|
|
=head1 Search::Estraier::Document |
47 |
|
|
|
48 |
|
|
Document for HyperEstraier |
49 |
|
|
|
50 |
|
|
=head2 new |
51 |
|
|
|
52 |
|
|
my $doc = new Search::HyperEstraier::Document; |
53 |
|
|
|
54 |
|
|
=cut |
55 |
|
|
|
56 |
|
|
sub new { |
57 |
|
|
my $class = shift; |
58 |
|
|
my $self = {@_}; |
59 |
|
|
bless($self, $class); |
60 |
|
|
|
61 |
dpavlin |
6 |
$self->{id} = -1; |
62 |
|
|
|
63 |
dpavlin |
2 |
$self ? return $self : return undef; |
64 |
|
|
} |
65 |
|
|
|
66 |
dpavlin |
4 |
|
67 |
dpavlin |
2 |
=head2 add_attr |
68 |
|
|
|
69 |
dpavlin |
6 |
Add an attribute. |
70 |
|
|
|
71 |
dpavlin |
2 |
$doc->add_attr( name => 'value' ); |
72 |
|
|
|
73 |
dpavlin |
5 |
B<FIXME>: delete attribute using |
74 |
|
|
|
75 |
|
|
$doc->add_attr( name => undef ); |
76 |
|
|
|
77 |
dpavlin |
2 |
=cut |
78 |
|
|
|
79 |
|
|
sub add_attr { |
80 |
|
|
my $self = shift; |
81 |
|
|
my $attrs = {@_}; |
82 |
|
|
|
83 |
|
|
while (my ($name, $value) = each %{ $attrs }) { |
84 |
dpavlin |
5 |
push @{ $self->{attrs}->{_s($name)} }, _s($value); |
85 |
dpavlin |
2 |
} |
86 |
|
|
} |
87 |
|
|
|
88 |
dpavlin |
5 |
|
89 |
|
|
=head2 add_text |
90 |
|
|
|
91 |
dpavlin |
6 |
Add a sentence of text. |
92 |
|
|
|
93 |
dpavlin |
5 |
$doc->add_text('this is example text to display'); |
94 |
|
|
|
95 |
|
|
=cut |
96 |
|
|
|
97 |
|
|
sub add_text { |
98 |
|
|
my $self = shift; |
99 |
|
|
my $text = shift; |
100 |
|
|
return unless defined($text); |
101 |
|
|
|
102 |
|
|
push @{ $self->{dtexts} }, _s($text); |
103 |
|
|
} |
104 |
|
|
|
105 |
|
|
|
106 |
|
|
=head2 add_hidden_text |
107 |
|
|
|
108 |
dpavlin |
6 |
Add a hidden sentence. |
109 |
|
|
|
110 |
dpavlin |
5 |
$doc->add_hidden_text('this is example text just for search'); |
111 |
|
|
|
112 |
|
|
=cut |
113 |
|
|
|
114 |
|
|
sub add_hidden_text { |
115 |
|
|
my $self = shift; |
116 |
|
|
my $text = shift; |
117 |
|
|
return unless defined($text); |
118 |
|
|
|
119 |
|
|
push @{ $self->{htexts} }, _s($text); |
120 |
|
|
} |
121 |
|
|
|
122 |
dpavlin |
6 |
=head2 id |
123 |
|
|
|
124 |
|
|
Get the ID number of document. If the object has never been registred, C<-1> is returned. |
125 |
|
|
|
126 |
|
|
print $doc->id; |
127 |
|
|
|
128 |
|
|
=cut |
129 |
|
|
|
130 |
|
|
sub id { |
131 |
|
|
my $self = shift; |
132 |
|
|
return $self->{id}; |
133 |
|
|
} |
134 |
|
|
|
135 |
dpavlin |
5 |
=head2 dump_draft |
136 |
|
|
|
137 |
|
|
print $doc->dump_draft; |
138 |
|
|
|
139 |
|
|
=cut |
140 |
|
|
|
141 |
|
|
sub dump_draft { |
142 |
|
|
} |
143 |
|
|
|
144 |
dpavlin |
4 |
=head2 delete |
145 |
dpavlin |
2 |
|
146 |
dpavlin |
4 |
Empty document object |
147 |
dpavlin |
2 |
|
148 |
dpavlin |
4 |
$doc->delete; |
149 |
|
|
|
150 |
|
|
=cut |
151 |
|
|
|
152 |
|
|
sub delete { |
153 |
|
|
my $self = shift; |
154 |
|
|
|
155 |
dpavlin |
5 |
foreach my $data (qw/attrs dtexts stexts/) { |
156 |
|
|
delete($self->{$data}); |
157 |
|
|
} |
158 |
dpavlin |
4 |
|
159 |
|
|
return 1; |
160 |
|
|
} |
161 |
|
|
|
162 |
|
|
|
163 |
|
|
=head2 _s |
164 |
|
|
|
165 |
|
|
Remove multiple whitespaces from string, as well as whitespaces at beginning or end |
166 |
|
|
|
167 |
|
|
my $text = _s(" this is a text "); |
168 |
|
|
$text = 'this is a text'; |
169 |
|
|
|
170 |
|
|
=cut |
171 |
|
|
|
172 |
|
|
sub _s { |
173 |
|
|
my $text = shift || return; |
174 |
|
|
$text =~ s/\s\s+/ /gs; |
175 |
|
|
$text =~ s/^\s+//; |
176 |
|
|
$text =~ s/\s+$//; |
177 |
|
|
return $text; |
178 |
|
|
} |
179 |
|
|
|
180 |
|
|
|
181 |
|
|
|
182 |
dpavlin |
2 |
package Search::Estraier::Master; |
183 |
|
|
|
184 |
|
|
use Carp; |
185 |
|
|
|
186 |
|
|
=head1 Search::Estraier::Master |
187 |
|
|
|
188 |
|
|
Controll node master. This requires user with administration priviledges. |
189 |
|
|
|
190 |
|
|
=cut |
191 |
|
|
|
192 |
|
|
{ |
193 |
|
|
package RequestAgent; |
194 |
|
|
@ISA = qw(LWP::UserAgent); |
195 |
|
|
|
196 |
|
|
sub new { |
197 |
|
|
my $self = LWP::UserAgent::new(@_); |
198 |
|
|
$self->agent("Search-Estraier/$Search::Estraer::VERSION"); |
199 |
|
|
$self; |
200 |
|
|
} |
201 |
|
|
|
202 |
|
|
sub get_basic_credentials { |
203 |
|
|
my($self, $realm, $uri) = @_; |
204 |
|
|
# return ($user, $password); |
205 |
|
|
} |
206 |
|
|
} |
207 |
|
|
|
208 |
|
|
|
209 |
|
|
|
210 |
|
|
=head2 new |
211 |
|
|
|
212 |
|
|
Create new connection to node master. |
213 |
|
|
|
214 |
|
|
my $master = new Search::Estraier::Master( |
215 |
|
|
url => 'http://localhost:1978', |
216 |
|
|
user => 'admin', |
217 |
|
|
passwd => 'admin', |
218 |
|
|
); |
219 |
|
|
|
220 |
|
|
=cut |
221 |
|
|
|
222 |
|
|
sub new { |
223 |
|
|
my $class = shift; |
224 |
|
|
my $self = {@_}; |
225 |
|
|
bless($self, $class); |
226 |
|
|
|
227 |
|
|
foreach my $p (qw/url user passwd/) { |
228 |
|
|
croak "need $p" unless ($self->{$p}); |
229 |
|
|
} |
230 |
|
|
|
231 |
|
|
$self ? return $self : return undef; |
232 |
|
|
} |
233 |
|
|
|
234 |
|
|
|
235 |
|
|
|
236 |
|
|
### |
237 |
|
|
|
238 |
|
|
=head1 EXPORT |
239 |
|
|
|
240 |
|
|
Nothing. |
241 |
|
|
|
242 |
|
|
=head1 SEE ALSO |
243 |
|
|
|
244 |
|
|
L<http://hyperestraier.sourceforge.net/> |
245 |
|
|
|
246 |
|
|
Hyper Estraier Ruby interface on which this module is based. |
247 |
|
|
|
248 |
|
|
=head1 AUTHOR |
249 |
|
|
|
250 |
|
|
Dobrica Pavlinusic, E<lt>dpavlin@rot13.orgE<gt> |
251 |
|
|
|
252 |
|
|
|
253 |
|
|
=head1 COPYRIGHT AND LICENSE |
254 |
|
|
|
255 |
|
|
Copyright (C) 2005 by Dobrica Pavlinusic |
256 |
|
|
|
257 |
|
|
This library is free software; you can redistribute it and/or modify |
258 |
|
|
it under the GPL v2 or later. |
259 |
|
|
|
260 |
|
|
=cut |
261 |
|
|
|
262 |
|
|
1; |