13 |
|
|
14 |
=head1 NAME |
=head1 NAME |
15 |
|
|
16 |
SWISH::PlusPlus - Perl extension SWISH++ |
SWISH::PlusPlus - Perl extension for full-text indexer SWISH++ with properties support |
17 |
|
|
18 |
=head1 SYNOPSIS |
=head1 SYNOPSIS |
19 |
|
|
23 |
=head1 DESCRIPTION |
=head1 DESCRIPTION |
24 |
|
|
25 |
This is perl module to use SWISH++ indexer by Paul J. Lucas. SWISH++ is |
This is perl module to use SWISH++ indexer by Paul J. Lucas. SWISH++ is |
26 |
rewrite of swish-e in C++ which is extremly fast (thank to mmap), but without |
rewrite of swish-e in C++ which is extremely fast (due to mmap usage and |
27 |
support for properties (which this module tries to fix). |
clever language heuristics), but without support for properties (which this |
28 |
|
module tries to fix). |
29 |
Implementation of this module is crafted after L<Plucene::Simple> and it |
|
30 |
should be easy to replace Plucene with this module for increased |
Implementation of API is something in-between C<SWISH::API> and |
31 |
performance. However, this module is not plug-in replacement. |
C<Plucene::Simple>. It should be easy to replace Plucene or swish-e with |
32 |
|
this module for increased performance. However, this module is not plug-in |
33 |
|
replacement. |
34 |
|
|
35 |
=head1 METHODS |
=head1 METHODS |
36 |
|
|
37 |
=head2 new |
=head2 new |
38 |
|
|
39 |
Create new indexing object. |
Create new instance for index. |
40 |
|
|
41 |
my $i = SWISH::PlusPlus->new( |
my $i = SWISH::PlusPlus->new( |
42 |
index_dir => '/path/to/index', |
index_dir => '/path/to/index', |
47 |
use_stopwords => 1, |
use_stopwords => 1, |
48 |
); |
); |
49 |
|
|
50 |
Options to new are following: |
Options are described below: |
51 |
|
|
52 |
=over 5 |
=over 5 |
53 |
|
|
54 |
=item C<index_dir> |
=item C<index_dir> |
55 |
|
|
56 |
Path to directory in which index will be created. |
Path to directory in which index and meta database will be created. |
57 |
|
|
58 |
=item C<index> |
=item C<index> |
59 |
|
|
73 |
=item C<meta_in_body> |
=item C<meta_in_body> |
74 |
|
|
75 |
This option (off by default) enables to search content of meta fields |
This option (off by default) enables to search content of meta fields |
76 |
without specifing them (like they are in body of document). This will |
without specifying them (like they are in body of document). This will |
77 |
somewhat increate index size. |
somewhat increase index size. |
78 |
|
|
79 |
=item C<use_stopwords> |
=item C<use_stopwords> |
80 |
|
|
121 |
|
|
122 |
=head2 check_bin |
=head2 check_bin |
123 |
|
|
124 |
Check if swish++ binaries specified in L<new> are available and verify |
Check if SWISH++ binaries specified in L<new> are available and verify |
125 |
version signature. |
version signature. |
126 |
|
|
127 |
if ($i->check_bin) { |
if ($i->check_bin) { |
132 |
|
|
133 |
$i->{'version'} |
$i->{'version'} |
134 |
|
|
135 |
which you can examine to see version. |
which you can examined to see numeric version (something like C<6.0.4>). |
136 |
|
|
137 |
=cut |
=cut |
138 |
|
|
163 |
|
|
164 |
Quick way to add simple data to index. |
Quick way to add simple data to index. |
165 |
|
|
166 |
$i->index_document($key, $data); |
$i->index_document($path, $data); |
167 |
$i->index_document( 42 => 'meaning of life' ); |
$i->index_document( 42 => 'meaning of life' ); |
168 |
|
|
169 |
|
C<$path> value is really path, so you don't want to use directory |
170 |
|
separators (slashes, /) in it probably. |
171 |
|
|
172 |
=cut |
=cut |
173 |
|
|
174 |
sub index_document { |
sub index_document { |
188 |
|
|
189 |
=head2 add |
=head2 add |
190 |
|
|
191 |
Add document with metadata to index. |
Add document with meta-data to index. |
192 |
|
|
193 |
$i->add( |
$i->add( |
194 |
path => 'path/to/document', |
path => 'path/to/document', |
212 |
|
|
213 |
return 1; |
return 1; |
214 |
} |
} |
215 |
|
|
216 |
=head2 search |
=head2 search |
217 |
|
|
218 |
Search your index. |
Search your index using any valid SWISH++ query. |
219 |
|
|
220 |
|
my @results = $i->search("swish query"); |
221 |
|
|
222 |
my @results = $i->search("swhish query"); |
Returns array with elements like this: |
223 |
|
|
224 |
Returns array with result IDs. |
{ |
225 |
|
rank => 10, # rank of result |
226 |
|
path => 'path to result', # path to result |
227 |
|
size => 999, # size in bytes |
228 |
|
title => 'title of result' # title meta property |
229 |
|
} |
230 |
|
|
231 |
=cut |
=cut |
232 |
|
|
298 |
|
|
299 |
=head2 finish_update |
=head2 finish_update |
300 |
|
|
301 |
This method will close index. |
This method will close index binary and enable search. Searching is not |
302 |
|
available while indexing is in process. |
303 |
|
|
304 |
$i->finish_update; |
$i->finish_update; |
305 |
|
|
306 |
It will be called on DESTROY when $i goes out of scope. |
Usually, you don't need to call this method directly. It will be called on |
307 |
|
DESTROY when $i goes out of scope or when you first call search in session |
308 |
|
if indexing was started. |
309 |
|
|
310 |
=cut |
=cut |
311 |
|
|
324 |
|
|
325 |
=head1 PRIVATE METHODS |
=head1 PRIVATE METHODS |
326 |
|
|
327 |
Private methods implement internals for creating temporary file needed for |
Private methods implement internals for creating temporary files needed for |
328 |
swish++. You should have no need to call them directly, and they are here |
SWISH++. You should have no need to call them directly, and they are here |
329 |
just to have documentation. |
just to have documentation. |
330 |
|
|
331 |
=head2 _init_indexer |
=head2 _init_indexer |
375 |
return $self->{'_index_fh'}; |
return $self->{'_index_fh'}; |
376 |
} |
} |
377 |
|
|
|
=head2 _tie_meta_db |
|
|
|
|
|
Open BerkeleyDB database with meta properties. |
|
|
|
|
|
$i->_tie_meta_db(DB_CREATE); |
|
|
$i->_tie_meta_db(DB_RDONLY); |
|
|
|
|
|
} |
|
|
|
|
|
=cut |
|
|
|
|
|
sub _tie_meta_db { |
|
|
my $self = shift; |
|
|
|
|
|
my $flags = shift || confess "need DB_CREATE or DB_RDONLY"; |
|
|
|
|
|
return if ($self->{'_meta_db_flags'} && $self->{'_meta_db_flags'} == $flags); |
|
|
|
|
|
print STDERR "## _tie_meta_db($flags)\n" if ($self->{'debug'}); |
|
|
|
|
|
$self->_untie_meta_db; |
|
|
$self->{'_meta_db_flags'} = $flags; |
|
|
|
|
|
my $file = $self->{'index_dir'}.'/meta.db'; |
|
|
|
|
|
tie %{$self->{'meta_db'}}, "BerkeleyDB::Hash", |
|
|
-Filename => $file, |
|
|
-Flags => $flags |
|
|
or confess "cannot open $file: $! $BerkeleyDB::Error\n" ; |
|
|
|
|
|
return 1; |
|
|
} |
|
|
|
|
|
=head2 _untie_meta_db |
|
|
|
|
|
Close BerkeleyDB database with meta properties. |
|
|
|
|
|
$i->_untie_meta_db |
|
|
|
|
|
=cut |
|
|
|
|
|
sub _untie_meta_db { |
|
|
my $self = shift; |
|
|
|
|
|
return unless ($self->{'meta_db'}); |
|
|
|
|
|
print STDERR "## _untie_meta_db\n" if ($self->{'debug'}); |
|
|
untie %{$self->{'meta_db'}} || confess "can't untie!"; |
|
|
undef $self->{'meta_db'}; |
|
|
undef $self->{'_meta_db_flags'}; |
|
|
|
|
|
return 1; |
|
|
} |
|
|
|
|
378 |
=head2 _create_doc |
=head2 _create_doc |
379 |
|
|
380 |
Create temporary file and pass it's name to swish++ |
Create temporary file and pass it's name to SWISH++ |
381 |
|
|
382 |
$i->_create_doc( |
$i->_create_doc( |
383 |
path => 'path/to/store/in/index', |
path => 'path/to/store/in/index', |
459 |
return 1; |
return 1; |
460 |
} |
} |
461 |
|
|
462 |
|
=head2 _tie_meta_db |
463 |
|
|
464 |
|
Open BerkeleyDB database with meta properties. |
465 |
|
|
466 |
|
$i->_tie_meta_db(DB_CREATE); |
467 |
|
$i->_tie_meta_db(DB_RDONLY); |
468 |
|
|
469 |
|
} |
470 |
|
|
471 |
|
=cut |
472 |
|
|
473 |
|
sub _tie_meta_db { |
474 |
|
my $self = shift; |
475 |
|
|
476 |
|
my $flags = shift || confess "need DB_CREATE or DB_RDONLY"; |
477 |
|
|
478 |
|
return if ($self->{'_meta_db_flags'} && $self->{'_meta_db_flags'} == $flags); |
479 |
|
|
480 |
|
print STDERR "## _tie_meta_db($flags)\n" if ($self->{'debug'}); |
481 |
|
|
482 |
|
$self->_untie_meta_db; |
483 |
|
$self->{'_meta_db_flags'} = $flags; |
484 |
|
|
485 |
|
my $file = $self->{'index_dir'}.'/meta.db'; |
486 |
|
|
487 |
|
tie %{$self->{'meta_db'}}, "BerkeleyDB::Hash", |
488 |
|
-Filename => $file, |
489 |
|
-Flags => $flags |
490 |
|
or confess "cannot open $file: $! $BerkeleyDB::Error\n" ; |
491 |
|
|
492 |
|
return 1; |
493 |
|
} |
494 |
|
|
495 |
|
=head2 _untie_meta_db |
496 |
|
|
497 |
|
Close BerkeleyDB database with meta properties. |
498 |
|
|
499 |
|
$i->_untie_meta_db; |
500 |
|
|
501 |
|
=cut |
502 |
|
|
503 |
|
sub _untie_meta_db { |
504 |
|
my $self = shift; |
505 |
|
|
506 |
|
return unless ($self->{'meta_db'}); |
507 |
|
|
508 |
|
print STDERR "## _untie_meta_db\n" if ($self->{'debug'}); |
509 |
|
untie %{$self->{'meta_db'}} || confess "can't untie!"; |
510 |
|
undef $self->{'meta_db'}; |
511 |
|
undef $self->{'_meta_db_flags'}; |
512 |
|
|
513 |
|
return 1; |
514 |
|
} |
515 |
|
|
516 |
1; |
1; |
517 |
__END__ |
__END__ |
518 |
|
|
524 |
|
|
525 |
=head2 Debian |
=head2 Debian |
526 |
|
|
527 |
Debian version of swish++ is often old (version 5 at moment of this writing |
Debian version of SWISH++ is often old (version 5 at moment of this writing |
528 |
while version 6 is available in source code), so this module by default |
while version 6 is available in source code), so this module by default |
529 |
uses executable names B<index> and B<search> for self-compiled version |
uses executable names B<index> and B<search> for self-compiled version |
530 |
instead of one from Debian package. See L<new> how to specify Debian |
instead of one from Debian package. See L<new> how to specify Debian |
532 |
|
|
533 |
=head2 SWISH++ |
=head2 SWISH++ |
534 |
|
|
535 |
Aside from very good rewrite in C++, SWISH++ is fatster because it has |
Aside from very good rewrite in C++, SWISH++ is faster because it uses |
536 |
claver heuristics about which data in input files are words to index and |
claver heuristics about which data in input files are words to index and |
537 |
which are not. It's based on English language and might be best choice if |
which are not. It's based on English language and might be best choice if |
538 |
you plan to install large amount of long text documents. |
you plan to index large amount of long text documents. |
539 |
|
|
540 |
However, if you plan to index all data from structured storage (e.g. RDBMS) |
However, if you plan to index all data from structured storage (e.g. RDBMS) |
541 |
you might want B<all> words from data to end up in index as opposed to just |
you might want B<all> words from data to end up in index as opposed to just |
543 |
don't plan to index English texts with this module. |
don't plan to index English texts with this module. |
544 |
|
|
545 |
With distribution build versions of SWISH++ you might have problems with |
With distribution build versions of SWISH++ you might have problems with |
546 |
disepearing words. To overcome this problem, you will have to compile and |
disapearing words. To overcome this problem, you will have to compile and |
547 |
configure SWISH++ yourself (because language characteristics are |
configure SWISH++ yourself (because language characteristics are |
548 |
compilation-time option). |
compilation-time option). |
549 |
|
|
559 |
doesn't recognize 2004-12-05 as date. Have in mind that your index size |
doesn't recognize 2004-12-05 as date. Have in mind that your index size |
560 |
might explode. |
might explode. |
561 |
|
|
562 |
|
=head1 BUGS |
563 |
|
|
564 |
|
Currently there is no way to specify which meta data will be stored as |
565 |
|
properties. B<This will be fixed very soon>. |
566 |
|
|
567 |
|
There is no garbage collection on temporary files created for SWISH++. This |
568 |
|
means that one run of indexer will take additional disk space for temporary |
569 |
|
files, which will be removed at end. There should be some way to remove |
570 |
|
files after they are indexed by SWISH++. However, at this early stage of |
571 |
|
development it's just not supported yet. Have plenty of disk space! |
572 |
|
|
573 |
=head1 SEE ALSO |
=head1 SEE ALSO |
574 |
|
|
575 |
C<swish++> web site L<http://homepage.mac.com/pauljlucas/software/swish/> |
SWISH++ web site L<http://homepage.mac.com/pauljlucas/software/swish/> |
576 |
|
|
577 |
=head1 AUTHOR |
=head1 AUTHOR |
578 |
|
|