lucy-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nick Wellnhofer <wellnho...@aevum.de>
Subject Re: [lucy-user] Cannot get the exact phrase match
Date Tue, 25 Dec 2012 14:45:54 GMT
Hi Alex,

It seems that you're using a stemmer in your analyzer chain when indexing documents. So the
term "consciousness" will be stemmed and stored as "conscious" in the database. This means
that you have to process your query with the same analyzer that's been used for indexing.
Instead of

    $query = Lucy::Search::TermQuery->new(
        field => $field,
        term  => $token,
    );

you should use something like the following:

    my $type     = $schema->fetch_type($field);
    my $analyzer = $type->get_analyzer;
    my $terms    = $analyzer->split($token);
    if ( @$terms == 1 ) {
        $query = Lucy::Search::TermQuery->new(
            field => $field,
            term  => $terms->[0],
        );
    }
    elsif ( @$terms > 1 ) {
        $query = Lucy::Search::PhraseQuery->new(
            field => $field,
            terms => $terms,
        );
    }

Lucy's built-in QueryParser class will do that for you. If you want to use a custom query
parser, you can find some documentation here:

http://lucy.apache.org/docs/perl/Lucy/Docs/Cookbook/CustomQueryParser.html

Nick


On Dec 25, 2012, at 15:03 , Aleksandar Radovanovic <Aleksandar@Radovanovic.com> wrote:

> Hi there,
> 
> I was trying to match a term exactly by using
> 
> Lucy::Search::PhraseQuery and Lucy::Search::TermQuery
> 
> but I could not get the exactly-exact match. For example, if I try to
> find the term "consciousness" (my text is full of it :-) I do not have
> any matches. However, the search for "conscious" gives me matches to
> "conscious" and to "consciousness". Since those are two different
> concepts I consider the result being incorrect.
> 
> Is there any way to get the exactly-exact match? (or perhaps I am doing
> something wrong).
> 
> Alex


Mime
View raw message