/[Search-Estraier]/trunk/lib/Search/Estraier.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/lib/Search/Estraier.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6 - (show annotations)
Wed Jan 4 14:48:11 2006 UTC (18 years, 3 months ago) by dpavlin
Original Path: trunk/Estraier.pm
File size: 3885 byte(s)
added id, documentation, rename of vars in test
1 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->{id} = -1;
62
63 $self ? return $self : return undef;
64 }
65
66
67 =head2 add_attr
68
69 Add an attribute.
70
71 $doc->add_attr( name => 'value' );
72
73 B<FIXME>: delete attribute using
74
75 $doc->add_attr( name => undef );
76
77 =cut
78
79 sub add_attr {
80 my $self = shift;
81 my $attrs = {@_};
82
83 while (my ($name, $value) = each %{ $attrs }) {
84 push @{ $self->{attrs}->{_s($name)} }, _s($value);
85 }
86 }
87
88
89 =head2 add_text
90
91 Add a sentence of text.
92
93 $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 Add a hidden sentence.
109
110 $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 =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 =head2 dump_draft
136
137 print $doc->dump_draft;
138
139 =cut
140
141 sub dump_draft {
142 }
143
144 =head2 delete
145
146 Empty document object
147
148 $doc->delete;
149
150 =cut
151
152 sub delete {
153 my $self = shift;
154
155 foreach my $data (qw/attrs dtexts stexts/) {
156 delete($self->{$data});
157 }
158
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 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;

  ViewVC Help
Powered by ViewVC 1.1.26