Hi Nick,
Thank you - it works perfectly!
I was wondering is there an easy solution for a related problem? For a
general documents search (user can type anything he wants) I was using
Lucy::Search::IndexSearcher with Lucy::Search::QueryParser hoping that
quoted phrases will be recognized and matched more, less correctly.
However, if I, for example, search for chemistry related phrase: OF(+)
search returns no result. On the other hand, the quoted phrase: "OF(+)"
returns every single document containing the preposition "of". The
highlighter clearly shows that "OF(+)" was still not not found as the
"(+)" part was not highlighted.
Is there an easy solution, or must I analyze the user's input and decide
what to use: IndexSearcher for non quoted queries and
TermQuery/PhraseQuery for quoted, or must I create some special regex
rules for words containing non-letters? There are many of these in
biomedical field.
I might be asking too much since even google does not get this right :-)
Alex
On 12/25/12 5:45 PM, Nick Wellnhofer wrote:
> 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
> <[email protected]> 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
>
>