Lucy::Simple - Basic search engine.
First, build an index of your documents.
my $index = Lucy::Simple->new( path => '/path/to/index/' language => 'en', ); while ( my ( $title, $content ) = each %source_docs ) { $index->add_doc({ title => $title, content => $content, }); }
Later, search the index.
my $total_hits = $index->search( query => $query_string, offset => 0, num_wanted => 10, ); print "Total hits: $total_hits\n"; while ( my $hit = $index->next ) { print "$hit->{title}\n", }
Lucy::Simple is a stripped-down interface for the Apache Lucy search engine library.
my $lucy = Lucy::Simple->new( path => '/path/to/index/', language => 'en', );
Create a Lucy::Simple object,
which can be used for both indexing and searching.
Both parameters path
and language
are required.
|-----------------------| | Language | ISO code | |-----------------------| | Danish | da | | Dutch | nl | | English | en | | Finnish | fi | | French | fr | | German | de | | Italian | it | | Norwegian | no | | Portuguese | pt | | Spanish | es | | Swedish | sv | | Russian | ru | |-----------------------|
$lucy->add_doc({ location => $url, title => $title, content => $content, });
Add a document to the index. The document must be supplied as a hashref, with field names as keys and content as values.
my $int = $simple->search( query => $query # required offset => $offset # default: 0 num_wanted => $num_wanted # default: 10 sort_spec => $sort_spec # default: undef );
Search the index.
Returns the total number of documents which match the query.
(This number is unlikely to match num_wanted
.)
offset
is taken into account.my $hit_doc = $simple->next();
Return the next hit, or undef when the iterator is exhausted.
Lucy::Simple isa Clownfish::Obj.
Copyright © 2010-2015 The Apache Software Foundation, Licensed under the
Apache License, Version 2.0.
Apache Lucy, Lucy, Apache, the Apache feather logo, and the Apache Lucy project logo are trademarks of The
Apache Software Foundation. All other marks mentioned may be trademarks or registered trademarks of their
respective owners.