Search::Mousse - A simple and fast inverted index
my $mousse = Search::Mousse->new( directory => $directory, name => 'recipes', ); my $recipe = $mousse->fetch("Hearty Russian Beet Soup"); my @recipes = $mousse->search("crumb"); my @recipe_keys = $mousse->search_keys("italian soup");
Search::Mousse provides a simple and fast inverted index.
It is intended for constant databases (this is why it can be fast). Documents have a key, keywords (which the document can later be search for with) and a value (which can be a Perl data structure or object).
Use Search::Mousse::Writer to construct a database.
The default stemmer is:
sub { my $words = lc shift; return uniq(split / /, $words); }
Why is it called Search::Mousse? Well, in culinary terms, mousses are simple to make, can include quite complicated ingredients, and are inverted before presentation.
The constructor takes a few arguments: the directory to store files in, and a name for the database. If you have a custom stemmer, also pass it in:
my $mousse = Search::Mousse->new( directory => $directory, name => 'recipes', ); my $mousse2 = Search::Mousse->new( directory => $directory, name => 'photos', stemmer => \&stemmer, );
If this is set to true, query terms are ANDed by default. Thus "white bread" would be parsed the same as "+white +bread":
$mousse->and(1);
Returns a value from the database, given a key:
my $recipe = $mousse->fetch("Hearty Russian Beet Soup");
If you have used Search::Mousse::Writer::Related to analyse the database, the fetch_related() method returns a list of values that are similar to the given key:
my @recipes = $mousse->fetch_related("Hearty Russian Beet Soup");
If you have used Search::Mousse::Writer::Related to analyse the database, the fetch_related_keys() method returns a list of keys that are similar to the given key:
my @keys = $mousse->fetch_related_keys("Hearty Russian Beet Soup");
Returns a list of values that match the search terms (but see and()):
my @white_or_bread = $mousse->search("white bread"); my @white_bread = $mousse->search("+white +bread"); my @nonwhite_bread = $mousse->search("-white +bread");
Returns a list of keys that have all the keywords passed:
my @recipe_keys = $mousse->search_keys("italian soup");
Search::Mousse::Writer, Search::Mousse::Writer::Related
Leon Brocard, <acme@astray.com>
<acme@astray.com>
Copyright (C) 2005, Leon Brocard
This module is free software; you can redistribute it or modify it under the same terms as Perl itself.
To install Search::Mousse, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Search::Mousse
CPAN shell
perl -MCPAN -e shell install Search::Mousse
For more information on module installation, please visit the detailed CPAN module installation guide.