--- trunk/PlusPlus.pm 2004/12/03 19:35:02 4 +++ trunk/PlusPlus.pm 2004/12/04 17:49:20 8 @@ -8,6 +8,7 @@ use Carp; use File::Temp qw/ tempdir /; +#use YAML; =head1 NAME @@ -38,6 +39,7 @@ index_dir => '/path/to/index', index => 'index++', search => 'search++', + debug => 1, ); Options to open are following: @@ -58,6 +60,11 @@ Full or partial path to SWISH++ search executable. By default, it's B. +=item C + +This option (off by default) will produce a lot of debugging output on +C prefixed by C<##>. + =back =cut @@ -79,6 +86,8 @@ $self->{'index'} ||= 'index'; $self->{'search'} ||= 'search'; + print STDERR "## open index_dir: ",$self->{'index_dir'}," index: ",$self->{'index'}, " search: ",$self->{'search'},"\n" if ($self->{'debug'}); + $self ? return $self : return undef; } @@ -146,6 +155,52 @@ return 1; } +=head2 search + +Search your index. + + my @results = $i->search("swhish query"); + +Returns array with result IDs. + +=cut + +sub search { + my $self = shift; + + my $query = shift || return; + + $self->_close_index; + + my @results; + + # escape double quotes in query for shell + $query =~ s/"/\\"/g; + + my $open_cmd = $self->{'search'}." -i ".$self->{'index_dir'}.'/index "'.$query.'" |'; + print STDERR "## search $open_cmd\n" if ($self->{'debug'}); + + CORE::open(SEARCH, $open_cmd) || confess "can't start $open_cmd: $!"; + while() { + next if (/^#/); + chomp; + print STDERR "## $_\n" if ($self->{'debug'}); + my ($rank,$path,$size,$title) = split(/ /,$_,4); + push @results, { + rank => $rank, + path => $path, + size => $size, + title => $title, + } + } + + close(SEARCH) || confess "can't close search"; + + #print STDERR "## results: ",Dump(@results),"\n" if ($self->{'debug'}); + + return @results; +} + =head1 PRIVATE METHODS Private methods implement internals for creating temporary file needed for @@ -168,7 +223,7 @@ my $opt = "-v 4"; - my $open_cmd = '| index '.$opt.' -e "html:*" -i '.$self->{'index_dir'}.'/index -'; + my $open_cmd = '| '.$self->{'index'}.' '.$opt.' -e "html:*" -i '.$self->{'index_dir'}.'/index -'; chdir $self->{'tmp_dir'} || confess "can't chdir to ".$self->{'tmp_dir'}.": $!"; @@ -190,6 +245,8 @@ } ); +To delete document, just omit body and meta data. + =cut sub _create_doc { @@ -217,6 +274,27 @@ print { $self->{'index_fh'} } $arg->{'path'}."\n"; } +=head2 _close_index + +Close index after indexing. + + $i->_close_index; + +You have to close index before searching. + +=cut + +sub _close_index { + my $self = shift; + + return unless ($self->{'index_fh'}); + + print STDERR "## close index\n" if ($self->{'debug'}); + + close($self->{'index_fh'}); + undef $self->{'index_fh'}; +} + 1; __END__ @@ -234,20 +312,34 @@ instead of one from Debian package. See L how to specify Debian default binaries B and B. -=head1 SEE ALSO +=head2 SWISH++ -Mention other useful documentation such as the documentation of -related modules or operating system documentation (such as man pages -in UNIX), or any relevant external documentation such as RFCs or -standards. +Aside from very good rewrite in C++, SWISH++ is fatster because it has +claver heuristics about which data in input files are words to index and +which are not. It's based on English language and might be best choice if +you plan to install large amount of long text documents. + +However, if you plan to index all data from structured storage (e.g. RDBMS) +you might want B words from data to end up in index as opposed to just +those which look like English words. This is especially important if you +don't plan to index English texts with this module. + +With distribution build versions of SWISH++ you might have problems with +disepearing words. To overcome this problem, you will have to compile and +configure SWISH++ yourself (because language characteristics are +compilation-time option). + +Compilation of SWISH++ is easy process well described on project's web +pages. To see my very relaxed sample configuration take a look at C +directory included in distribution. -If you have a mailing list set up for your module, mention it here. +=head1 SEE ALSO -If you have a web site set up for your module, mention it here. +C web site L =head1 AUTHOR -Dobrica Pavlinusic, Edpavlin@E +Dobrica Pavlinusic, Edpavlin@rot13.orgE =head1 COPYRIGHT AND LICENSE