You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@lucy.apache.org by Saurabh Vasekar <sv...@listenlogic.com> on 2012/06/14 20:25:17 UTC

[lucy-user] Problem in implementing NOTQuery

Hello,

I want to implement the following specification.
My indexed document has 2 fields -- field1 and field2. I formed the
following query -

my $query1 = Lucy::Search::TermQuery->new(
         field => 'field1',
         term => 'term1'.
);

my $query2 = Lucy::Search::TermQuery->new(
        field => 'field2',
        term => 'term2',
);

my $query1NOT = Lucy::Search::NOTQuery->new(
        negated_query => $query1,
);

my $query = Lucy::Search::ANDQuery->new(
       children => [$query1NOT, $query2 ]
);

my $hits = $searcher->hits(
        query => $query,
        offset => $offset,
        num_wanted => $page_size,
);

The problem is that query1 is not being negated. I am getting results which
have both term1 and term2 whereas the result should contain only term2.

Is my implementation wrong? Is there any better method to do this?

Thank you.

Re: [lucy-user] Problem in implementing NOTQuery

Posted by Peter Karman <pe...@peknet.com>.
Saurabh Vasekar wrote on 6/14/12 1:25 PM:
> Hello,
> 
> I want to implement the following specification.
> My indexed document has 2 fields -- field1 and field2. I formed the
> following query -
> 
> my $query1 = Lucy::Search::TermQuery->new(
>          field => 'field1',
>          term => 'term1'.
> );
> 
> my $query2 = Lucy::Search::TermQuery->new(
>         field => 'field2',
>         term => 'term2',
> );
> 
> my $query1NOT = Lucy::Search::NOTQuery->new(
>         negated_query => $query1,
> );
> 
> my $query = Lucy::Search::ANDQuery->new(
>        children => [$query1NOT, $query2 ]
> );
> 
> my $hits = $searcher->hits(
>         query => $query,
>         offset => $offset,
>         num_wanted => $page_size,
> );
> 
> The problem is that query1 is not being negated. I am getting results which
> have both term1 and term2 whereas the result should contain only term2.
> 
> Is my implementation wrong? Is there any better method to do this?
> 

The syntax looks right to me.

It's hard to tell if you've implemented this right or wrong since the use case
you provide isn't complete. E.g., I don't know what is in the index. A fully
runnable piece of code would help.

I use NOT queries all the time with Search::Query::Dialect::Lucy, so I know the
Lucy feature works.


-- 
Peter Karman  .  http://peknet.com/  .  peter@peknet.com