4 |
use strict; |
use strict; |
5 |
use warnings; |
use warnings; |
6 |
|
|
|
require Exporter; |
|
|
|
|
|
our @ISA = qw(Exporter); |
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ qw( |
|
|
) ] ); |
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
|
|
|
|
|
our @EXPORT = qw( |
|
|
); |
|
|
|
|
7 |
our $VERSION = '0.00'; |
our $VERSION = '0.00'; |
8 |
|
|
|
use Carp; |
|
|
|
|
9 |
=head1 NAME |
=head1 NAME |
10 |
|
|
11 |
Search::Estraier - pure perl module to use Hyper Estraier search engine |
Search::Estraier - pure perl module to use Hyper Estraier search engine |
27 |
|
|
28 |
=cut |
=cut |
29 |
|
|
30 |
|
=head2 _s |
31 |
|
|
32 |
|
Remove multiple whitespaces from string, as well as whitespaces at beginning or end |
33 |
|
|
34 |
|
my $text = $self->_s(" this is a text "); |
35 |
|
$text = 'this is a text'; |
36 |
|
|
37 |
|
=cut |
38 |
|
|
39 |
|
sub _s { |
40 |
|
my $text = $_[1] || return; |
41 |
|
$text =~ s/\s\s+/ /gs; |
42 |
|
$text =~ s/^\s+//; |
43 |
|
$text =~ s/\s+$//; |
44 |
|
return $text; |
45 |
|
} |
46 |
|
|
47 |
package Search::Estraier::Document; |
package Search::Estraier::Document; |
48 |
|
|
49 |
use Carp qw/croak confess/; |
use Carp qw/croak confess/; |
50 |
|
|
51 |
|
use Search::Estraier; |
52 |
|
our @ISA = qw/Search::Estraier/; |
53 |
|
|
54 |
=head1 Search::Estraier::Document |
=head1 Search::Estraier::Document |
55 |
|
|
56 |
This class implements Document which is collection of attributes |
This class implements Document which is collection of attributes |
57 |
(key=value), vectors (also key value) display text and hidden text. |
(key=value), vectors (also key value) display text and hidden text. |
58 |
|
|
|
Document for HyperEstraier |
|
|
|
|
59 |
=head2 new |
=head2 new |
60 |
|
|
61 |
Create new document, empty or from draft. |
Create new document, empty or from draft. |
132 |
|
|
133 |
while (my ($name, $value) = each %{ $attrs }) { |
while (my ($name, $value) = each %{ $attrs }) { |
134 |
if (! defined($value)) { |
if (! defined($value)) { |
135 |
delete( $self->{attrs}->{_s($name)} ); |
delete( $self->{attrs}->{ $self->_s($name) } ); |
136 |
} else { |
} else { |
137 |
$self->{attrs}->{_s($name)} = _s($value); |
$self->{attrs}->{ $self->_s($name) } = $self->_s($value); |
138 |
} |
} |
139 |
} |
} |
140 |
|
|
155 |
my $text = shift; |
my $text = shift; |
156 |
return unless defined($text); |
return unless defined($text); |
157 |
|
|
158 |
push @{ $self->{dtexts} }, _s($text); |
push @{ $self->{dtexts} }, $self->_s($text); |
159 |
} |
} |
160 |
|
|
161 |
|
|
172 |
my $text = shift; |
my $text = shift; |
173 |
return unless defined($text); |
return unless defined($text); |
174 |
|
|
175 |
push @{ $self->{htexts} }, _s($text); |
push @{ $self->{htexts} }, $self->_s($text); |
176 |
} |
} |
177 |
|
|
178 |
=head2 id |
=head2 id |
284 |
|
|
285 |
$doc->delete; |
$doc->delete; |
286 |
|
|
287 |
|
This function is addition to original Ruby API, and since it was included in C wrappers it's here as a |
288 |
|
convinience. Document objects which go out of scope will be destroyed |
289 |
|
automatically. |
290 |
|
|
291 |
=cut |
=cut |
292 |
|
|
293 |
sub delete { |
sub delete { |
303 |
} |
} |
304 |
|
|
305 |
|
|
|
=head2 _s |
|
306 |
|
|
307 |
Remove multiple whitespaces from string, as well as whitespaces at beginning or end |
package Search::Estraier::Condition; |
308 |
|
|
309 |
my $text = _s(" this is a text "); |
use Carp qw/confess croak/; |
310 |
$text = 'this is a text'; |
|
311 |
|
use Search::Estraier; |
312 |
|
our @ISA = qw/Search::Estraier/; |
313 |
|
|
314 |
|
=head1 Search::Estraier::Condition |
315 |
|
|
316 |
|
=head2 new |
317 |
|
|
318 |
|
my $cond = new Search::HyperEstraier::Condition; |
319 |
|
|
320 |
=cut |
=cut |
321 |
|
|
322 |
sub _s { |
sub new { |
323 |
my $text = shift || return; |
my $class = shift; |
324 |
$text =~ s/\s\s+/ /gs; |
my $self = {}; |
325 |
$text =~ s/^\s+//; |
bless($self, $class); |
326 |
$text =~ s/\s+$//; |
|
327 |
return $text; |
$self ? return $self : return undef; |
328 |
} |
} |
329 |
|
|
330 |
|
=head2 set_phrase |
331 |
|
|
332 |
|
$cond->set_phrase('search phrase'); |
333 |
|
|
334 |
|
=cut |
335 |
|
|
336 |
|
sub set_phrase { |
337 |
|
my $self = shift; |
338 |
|
$self->{phrase} = $self->_s( shift ); |
339 |
|
} |
340 |
|
|
341 |
|
=head2 add_attr |
342 |
|
|
343 |
|
$cond->add_attr('@URI STRINC /~dpavlin/'); |
344 |
|
|
345 |
|
=cut |
346 |
|
|
347 |
|
sub add_attr { |
348 |
|
my $self = shift; |
349 |
|
my $attr = shift || return; |
350 |
|
push @{ $self->{attrs} }, $self->_s( $attr ); |
351 |
|
} |
352 |
|
|
353 |
|
=head2 set_order |
354 |
|
|
355 |
|
$cond->set_order('@mdate NUMD'); |
356 |
|
|
357 |
|
=cut |
358 |
|
|
359 |
|
sub set_order { |
360 |
|
my $self = shift; |
361 |
|
$self->{order} = shift; |
362 |
|
} |
363 |
|
|
364 |
|
=head2 set_max |
365 |
|
|
366 |
|
$cond->set_max(42); |
367 |
|
|
368 |
|
=cut |
369 |
|
|
370 |
|
sub set_max { |
371 |
|
my $self = shift; |
372 |
|
my $max = shift; |
373 |
|
croak "set_max needs number" unless ($max =~ m/^\d+$/); |
374 |
|
$self->{max} = $max; |
375 |
|
} |
376 |
|
|
377 |
|
=head2 set_options |
378 |
|
|
379 |
|
$cond->set_options( SURE => 1 ); |
380 |
|
|
381 |
|
=cut |
382 |
|
|
383 |
|
my $options = { |
384 |
|
# check N-gram keys skipping by three |
385 |
|
SURE => 1 << 0, |
386 |
|
# check N-gram keys skipping by two |
387 |
|
USUAL => 1 << 1, |
388 |
|
# without TF-IDF tuning |
389 |
|
FAST => 1 << 2, |
390 |
|
# with the simplified phrase |
391 |
|
AGITO => 1 << 3, |
392 |
|
# check every N-gram key |
393 |
|
NOIDF => 1 << 4, |
394 |
|
# check N-gram keys skipping by one |
395 |
|
SIMPLE => 1 << 10, |
396 |
|
}; |
397 |
|
|
398 |
|
sub set_options { |
399 |
|
my $self = shift; |
400 |
|
my $option = shift; |
401 |
|
confess "unknown option" unless ($options->{$option}); |
402 |
|
$self->{options} ||= $options->{$option}; |
403 |
|
} |
404 |
|
|
405 |
|
=head2 phrase |
406 |
|
|
407 |
|
Return search phrase. |
408 |
|
|
409 |
|
print $cond->phrase; |
410 |
|
|
411 |
|
=cut |
412 |
|
|
413 |
|
sub phrase { |
414 |
|
my $self = shift; |
415 |
|
return $self->{phrase}; |
416 |
|
} |
417 |
|
|
418 |
|
|
419 |
package Search::Estraier::Master; |
package Search::Estraier::Master; |
428 |
|
|
429 |
{ |
{ |
430 |
package RequestAgent; |
package RequestAgent; |
431 |
@ISA = qw(LWP::UserAgent); |
our @ISA = qw(LWP::UserAgent); |
432 |
|
|
433 |
sub new { |
sub new { |
434 |
my $self = LWP::UserAgent::new(@_); |
my $self = LWP::UserAgent::new(@_); |
489 |
|
|
490 |
=head1 COPYRIGHT AND LICENSE |
=head1 COPYRIGHT AND LICENSE |
491 |
|
|
492 |
Copyright (C) 2005 by Dobrica Pavlinusic |
Copyright (C) 2005-2006 by Dobrica Pavlinusic |
493 |
|
|
494 |
This library is free software; you can redistribute it and/or modify |
This library is free software; you can redistribute it and/or modify |
495 |
it under the GPL v2 or later. |
it under the GPL v2 or later. |