Peter Karman

NAME

Search::Query::Dialect::Lucy - Lucy query dialect

SYNOPSIS

 use Lucy;
 use Search::Query;
 
 my ($idx, $query) = get_index_name_and_query();
 
 my $searcher = Lucy::Search::IndexSearcher->new( index => $idx );
 my $schema   = $searcher->get_schema();
 
 # build field mapping
 my %fields;
 for my $field_name ( @{ $schema->all_fields() } ) { 
     $fields{$field_name} = { 
         type     => $schema->fetch_type($field_name),
         analyzer => $schema->fetch_analyzer($field_name),
     };  
 }
 
 my $query_parser = Search::Query->parser(
     dialect        => 'Lucy',
     croak_on_error => 1,
     default_field  => 'foo',  # applied to "bare" terms with no field
     fields         => \%fields
 );
 
 my $parsed_query = $query_parser->parse($query);
 my $lucy_query   = $parsed_query->as_lucy_query();
 my $hits         = $searcher->hits( query => $lucy_query );

DESCRIPTION

Search::Query::Dialect::Lucy extends the Lucy::QueryParser syntax to support wildcards, proximity and ranges, in addition to the standard Search::Query features.

METHODS

This class is a subclass of Search::Query::Dialect. Only new or overridden methods are documented here.

BUILD

Sets Lucy-appropriate defaults. Can take the following params, also available as standard attribute methods.

wildcard

Default is '*'.

allow_single_wildcards

If true, terms like '*' and '?' are allowed as valid. If false, the Parser will croak if any term consists solely of a wildcard.

The default is false.

fuzzify

If true, a wildcard is automatically appended to each query term.

ignore_order_in_proximity

If true, the terms in a proximity query will be evaluated for matches regardless of the order in which they appear. For example, given a document excerpt like:

 foo bar bing

and a query like:

 "bing foo"~5

if ignore_order_in_proximity is true, the document would match. If ignore_order_in_proximity is false (the default), the document would not match.

stringify

Returns the Query object as a normalized string.

stringify_clause( leaf, prefix )

Called by stringify() to handle each Clause in the Query tree.

as_lucy_query

Returns the Dialect object as a Lucy::Search::Query-based object. The Dialect object is walked and converted to a Lucy::Searcher-compatible tree.

field_class

Returns "Search::Query::Field::Lucy".

AUTHOR

Peter Karman, <karman at cpan.org>

BUGS

Please report any bugs or feature requests to bug-search-query-dialect-Lucy at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Search-Query-Dialect-Lucy. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc Search::Query::Dialect::Lucy

You can also look for information at:

COPYRIGHT & LICENSE

Copyright 2010 Peter Karman.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.