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 |
|
|
$self ? return $self : return undef; |
62 |
|
|
} |
63 |
|
|
|
64 |
dpavlin |
4 |
|
65 |
dpavlin |
2 |
=head2 add_attr |
66 |
|
|
|
67 |
|
|
$doc->add_attr( name => 'value' ); |
68 |
|
|
|
69 |
dpavlin |
5 |
B<FIXME>: delete attribute using |
70 |
|
|
|
71 |
|
|
$doc->add_attr( name => undef ); |
72 |
|
|
|
73 |
dpavlin |
2 |
=cut |
74 |
|
|
|
75 |
|
|
sub add_attr { |
76 |
|
|
my $self = shift; |
77 |
|
|
my $attrs = {@_}; |
78 |
|
|
|
79 |
|
|
while (my ($name, $value) = each %{ $attrs }) { |
80 |
dpavlin |
5 |
push @{ $self->{attrs}->{_s($name)} }, _s($value); |
81 |
dpavlin |
2 |
} |
82 |
|
|
} |
83 |
|
|
|
84 |
dpavlin |
5 |
|
85 |
|
|
=head2 add_text |
86 |
|
|
|
87 |
|
|
$doc->add_text('this is example text to display'); |
88 |
|
|
|
89 |
|
|
=cut |
90 |
|
|
|
91 |
|
|
sub add_text { |
92 |
|
|
my $self = shift; |
93 |
|
|
my $text = shift; |
94 |
|
|
return unless defined($text); |
95 |
|
|
|
96 |
|
|
push @{ $self->{dtexts} }, _s($text); |
97 |
|
|
} |
98 |
|
|
|
99 |
|
|
|
100 |
|
|
=head2 add_hidden_text |
101 |
|
|
|
102 |
|
|
$doc->add_hidden_text('this is example text just for search'); |
103 |
|
|
|
104 |
|
|
=cut |
105 |
|
|
|
106 |
|
|
sub add_hidden_text { |
107 |
|
|
my $self = shift; |
108 |
|
|
my $text = shift; |
109 |
|
|
return unless defined($text); |
110 |
|
|
|
111 |
|
|
push @{ $self->{htexts} }, _s($text); |
112 |
|
|
} |
113 |
|
|
|
114 |
|
|
=head2 dump_draft |
115 |
|
|
|
116 |
|
|
print $doc->dump_draft; |
117 |
|
|
|
118 |
|
|
=cut |
119 |
|
|
|
120 |
|
|
sub dump_draft { |
121 |
|
|
} |
122 |
|
|
|
123 |
dpavlin |
4 |
=head2 delete |
124 |
dpavlin |
2 |
|
125 |
dpavlin |
4 |
Empty document object |
126 |
dpavlin |
2 |
|
127 |
dpavlin |
4 |
$doc->delete; |
128 |
|
|
|
129 |
|
|
=cut |
130 |
|
|
|
131 |
|
|
sub delete { |
132 |
|
|
my $self = shift; |
133 |
|
|
|
134 |
dpavlin |
5 |
foreach my $data (qw/attrs dtexts stexts/) { |
135 |
|
|
delete($self->{$data}); |
136 |
|
|
} |
137 |
dpavlin |
4 |
|
138 |
|
|
return 1; |
139 |
|
|
} |
140 |
|
|
|
141 |
|
|
|
142 |
|
|
=head2 _s |
143 |
|
|
|
144 |
|
|
Remove multiple whitespaces from string, as well as whitespaces at beginning or end |
145 |
|
|
|
146 |
|
|
my $text = _s(" this is a text "); |
147 |
|
|
$text = 'this is a text'; |
148 |
|
|
|
149 |
|
|
=cut |
150 |
|
|
|
151 |
|
|
sub _s { |
152 |
|
|
my $text = shift || return; |
153 |
|
|
$text =~ s/\s\s+/ /gs; |
154 |
|
|
$text =~ s/^\s+//; |
155 |
|
|
$text =~ s/\s+$//; |
156 |
|
|
return $text; |
157 |
|
|
} |
158 |
|
|
|
159 |
|
|
|
160 |
|
|
|
161 |
dpavlin |
2 |
package Search::Estraier::Master; |
162 |
|
|
|
163 |
|
|
use Carp; |
164 |
|
|
|
165 |
|
|
=head1 Search::Estraier::Master |
166 |
|
|
|
167 |
|
|
Controll node master. This requires user with administration priviledges. |
168 |
|
|
|
169 |
|
|
=cut |
170 |
|
|
|
171 |
|
|
{ |
172 |
|
|
package RequestAgent; |
173 |
|
|
@ISA = qw(LWP::UserAgent); |
174 |
|
|
|
175 |
|
|
sub new { |
176 |
|
|
my $self = LWP::UserAgent::new(@_); |
177 |
|
|
$self->agent("Search-Estraier/$Search::Estraer::VERSION"); |
178 |
|
|
$self; |
179 |
|
|
} |
180 |
|
|
|
181 |
|
|
sub get_basic_credentials { |
182 |
|
|
my($self, $realm, $uri) = @_; |
183 |
|
|
# return ($user, $password); |
184 |
|
|
} |
185 |
|
|
} |
186 |
|
|
|
187 |
|
|
|
188 |
|
|
|
189 |
|
|
=head2 new |
190 |
|
|
|
191 |
|
|
Create new connection to node master. |
192 |
|
|
|
193 |
|
|
my $master = new Search::Estraier::Master( |
194 |
|
|
url => 'http://localhost:1978', |
195 |
|
|
user => 'admin', |
196 |
|
|
passwd => 'admin', |
197 |
|
|
); |
198 |
|
|
|
199 |
|
|
=cut |
200 |
|
|
|
201 |
|
|
sub new { |
202 |
|
|
my $class = shift; |
203 |
|
|
my $self = {@_}; |
204 |
|
|
bless($self, $class); |
205 |
|
|
|
206 |
|
|
foreach my $p (qw/url user passwd/) { |
207 |
|
|
croak "need $p" unless ($self->{$p}); |
208 |
|
|
} |
209 |
|
|
|
210 |
|
|
$self ? return $self : return undef; |
211 |
|
|
} |
212 |
|
|
|
213 |
|
|
|
214 |
|
|
|
215 |
|
|
### |
216 |
|
|
|
217 |
|
|
=head1 EXPORT |
218 |
|
|
|
219 |
|
|
Nothing. |
220 |
|
|
|
221 |
|
|
=head1 SEE ALSO |
222 |
|
|
|
223 |
|
|
L<http://hyperestraier.sourceforge.net/> |
224 |
|
|
|
225 |
|
|
Hyper Estraier Ruby interface on which this module is based. |
226 |
|
|
|
227 |
|
|
=head1 AUTHOR |
228 |
|
|
|
229 |
|
|
Dobrica Pavlinusic, E<lt>dpavlin@rot13.orgE<gt> |
230 |
|
|
|
231 |
|
|
|
232 |
|
|
=head1 COPYRIGHT AND LICENSE |
233 |
|
|
|
234 |
|
|
Copyright (C) 2005 by Dobrica Pavlinusic |
235 |
|
|
|
236 |
|
|
This library is free software; you can redistribute it and/or modify |
237 |
|
|
it under the GPL v2 or later. |
238 |
|
|
|
239 |
|
|
=cut |
240 |
|
|
|
241 |
|
|
1; |