On 1/28/13 12:59 AM, Aleksandar Radovanovic wrote:
On 1/27/13 10:39 PM, Marvin Humphrey wrote:
On Sat, Jan 26, 2013 at 5:12 AM, Aleksandar Radovanovic
<[email protected]> wrote:
I was wondering can one search for a pattern of ordered keywords?  For
example, search for:

     bob book alice

returns two different documents containing sentences:

     bob quickly gives the book to alice
     alice gently gives the book to olivia and bob

If order matters, the correct match should be the first one only.  Google for
example, solves this problem with a phrase search:

     "bob * book * alice"

Is it possible to implement something similar by using Lucy?
Maybe LucyX::Search::ProximityQuery with a high value for "within"?

     my $analyzer = $searcher->get_schema->fetch_analyzer("content");
     my $terms    = $analyzer->split("bob book alice");
     my $proximity_query = LucyX::Search::ProximityQuery->new(
         field  => 'content',
         terms  => $terms,
         within => 1000,    # match within 1000 positions
     );
     my $hits = $searcher->hits( query => $proximity_query );

Marvin Humphrey
Thank you Marvin.
It would be nice to have something like Google's phrase search: "here's
looking * * kid"

Have a look at Search::Query with the Lucy dialect.

 my $query_parser = Search::Query->parser(
    query_class => 'Lucy',
    query_class_opts => {
        ignore_order_in_proximity => 0,  # the default
    },
    default_field => 'content',
 );

 my $string = qq/"here's looking * * kid"~10/;  # proximity within => 10

 my $query = $query_parser->parse($string);

 my $lucy_query = $query->as_lucy_query();

 my $hits = $lucy_searcher->hits( query => $lucy_query );


--
Peter Karman  .  http://peknet.com/  .  [email protected]

Reply via email to