You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Minh Kama Yie <mi...@nuix.com.au> on 2002/08/08 09:17:04 UTC

performing NOT queries

Hi all,

I'm relatively new to Lucene so this question may seem a little obvious but I'm having some problems which may be a result of a misunderstanding on my part.

A description of my problem is as follows:

I have indexed 30 documents and then create a BooleanQuery as follows:

BooleanQuery query = new BooleanQuery();
query.add(QueryParser.parse("myValue", myFieldName, myAnalyzer), true, false);

I then execute it against the indexes and receive 25 documents back.

So I was to then execute the a boolean query constructed like:

BooleanQuery query = new BooleanQuery();
query.add(QueryParser.parse("myValue", mFieldName, myAnalyzer), true, true);

I _should_ get the other 5 right?

Am I missing something here?

Thanks in advance guys, you guys do awesome work.

Regards,

Minh Kama Yie

This message is intended only for the named recipient. 
If you are not the intended recipient you are notified that
disclosing, copying, distributing or taking any action 
in reliance on the contents of this information is strictly 
prohibited.

Re: performing NOT queries

Posted by Minh Kama Yie <mi...@nuix.com.au>.
My apologies, I should have pointed out the section in the FAQ that says
otherwise to your suggestion:

Also, I am using 1.2 Final.

The FAQ answer was for question 9 in the "Searching" section.

The query it intends to do is: ('aaa' or 'bbb') and 'ddd') but not the
phrase 'happy dog'

The structure it suggests is:
  BooleanQuery

    BooleanQuery (required)

       BooleanQuery (Required)
          TermQuery 'aaa'
          Term 'bbb'

       BooleanQuery (Required)
          TermQuery 'ddd'

    PhraseQuery (prohibited, required)
       Term 'happy'
       Term 'dog'


----- Original Message -----
From: "Minh Kama Yie" <mi...@nuix.com.au>
To: "Lucene Users List" <lu...@jakarta.apache.org>; <ns...@bayt.net>
Sent: Thursday, August 08, 2002 6:35 PM
Subject: Re: performing NOT queries


> Hi Nader,
>
> Thanks for the quick reply!
>
> Yeah, I read that in the javadoc, but the FAQ seems to say otherwise (it
> says to set both prohibited AND required flags).
>
> I have also tried setting only the prohibited flag (as you are suggesting)
> but that doesn't return any results either. I have also tried using
> QueryParser. I simply added "NOT " in front of my term. That didn't work
> either.
>
> I am correct in assuming that my intended NOT query will return 5 rows?
>
> Thanks again.
>
> ----- Original Message -----
> From: "Nader S. Henein" <ns...@bayt.net>
> To: "Lucene Users List" <lu...@jakarta.apache.org>
> Sent: Thursday, August 08, 2002 6:32 PM
> Subject: RE: performing NOT queries
>
>
> > in the Lucene JAVADOC you see this :
> > /*
> > public final void add(Query query,
> >                       boolean required,
> >                       boolean prohibited)Adds a clause to a boolean
query.
> > Clauses may be:
> > required which means that documents which do not match this sub-query
will
> > not match the boolean query;
> > prohibited which means that documents which do match this sub-query will
> not
> > match the boolean query; or
> > neither, in which case matched documents are neither prohibited from nor
> > required to match the sub-query.
> >
> > It is an error to specify a clause as both required and prohibited.
> > */
> >
> > and you see that the last line states that "It is an error to specify a
> > clause as both required and prohibited."
> > so you can't so that, you need to think of these as on/off flags rather
> than
> > true and false from the boolean sense.
> >
> > so in your second query try :
> >
> > instead of this:
> >
> > BooleanQuery query = new BooleanQuery();
> > query.add(QueryParser.parse("myValue", mFieldName, myAnalyzer), true,
> true)
> >
> > try this:
> >
> > BooleanQuery query = new BooleanQuery();
> > query.add(QueryParser.parse("myValue", mFieldName, myAnalyzer), false,
> true)
> >
> > I hope this works, but by the way there are easier ways of doing a NOT,
> > check out the queryParser section of the JavaDocs
> >
> > Nader Henein
> >
> > -----Original Message-----
> > From: Minh Kama Yie [mailto:minh@nuix.com.au]
> > Sent: Thursday, August 08, 2002 11:17 AM
> > To: lucene-user@jakarta.apache.org
> > Subject: performing NOT queries
> >
> >
> > Hi all,
> >
> > I'm relatively new to Lucene so this question may seem a little obvious
> but
> > I'm having some problems which may be a result of a misunderstanding on
my
> > part.
> >
> > A description of my problem is as follows:
> >
> > I have indexed 30 documents and then create a BooleanQuery as follows:
> >
> > BooleanQuery query = new BooleanQuery();
> > query.add(QueryParser.parse("myValue", myFieldName, myAnalyzer), true,
> > false);
> >
> > I then execute it against the indexes and receive 25 documents back.
> >
> > So I was to then execute the a boolean query constructed like:
> >
> > BooleanQuery query = new BooleanQuery();
> > query.add(QueryParser.parse("myValue", mFieldName, myAnalyzer), true,
> true);
> >
> > I _should_ get the other 5 right?
> >
> > Am I missing something here?
> >
> > Thanks in advance guys, you guys do awesome work.
> >
> > Regards,
> >
> > Minh Kama Yie
> >
> > This message is intended only for the named recipient.
> > If you are not the intended recipient you are notified that
> > disclosing, copying, distributing or taking any action
> > in reliance on the contents of this information is strictly
> > prohibited.
> >
> >
> > --
> > To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> > For additional commands, e-mail:
> <ma...@jakarta.apache.org>
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: performing NOT queries

Posted by Minh Kama Yie <mi...@nuix.com.au>.
Hi Nader,

Thanks for the quick reply!

Yeah, I read that in the javadoc, but the FAQ seems to say otherwise (it
says to set both prohibited AND required flags).

I have also tried setting only the prohibited flag (as you are suggesting)
but that doesn't return any results either. I have also tried using
QueryParser. I simply added "NOT " in front of my term. That didn't work
either.

I am correct in assuming that my intended NOT query will return 5 rows?

Thanks again.

----- Original Message -----
From: "Nader S. Henein" <ns...@bayt.net>
To: "Lucene Users List" <lu...@jakarta.apache.org>
Sent: Thursday, August 08, 2002 6:32 PM
Subject: RE: performing NOT queries


> in the Lucene JAVADOC you see this :
> /*
> public final void add(Query query,
>                       boolean required,
>                       boolean prohibited)Adds a clause to a boolean query.
> Clauses may be:
> required which means that documents which do not match this sub-query will
> not match the boolean query;
> prohibited which means that documents which do match this sub-query will
not
> match the boolean query; or
> neither, in which case matched documents are neither prohibited from nor
> required to match the sub-query.
>
> It is an error to specify a clause as both required and prohibited.
> */
>
> and you see that the last line states that "It is an error to specify a
> clause as both required and prohibited."
> so you can't so that, you need to think of these as on/off flags rather
than
> true and false from the boolean sense.
>
> so in your second query try :
>
> instead of this:
>
> BooleanQuery query = new BooleanQuery();
> query.add(QueryParser.parse("myValue", mFieldName, myAnalyzer), true,
true)
>
> try this:
>
> BooleanQuery query = new BooleanQuery();
> query.add(QueryParser.parse("myValue", mFieldName, myAnalyzer), false,
true)
>
> I hope this works, but by the way there are easier ways of doing a NOT,
> check out the queryParser section of the JavaDocs
>
> Nader Henein
>
> -----Original Message-----
> From: Minh Kama Yie [mailto:minh@nuix.com.au]
> Sent: Thursday, August 08, 2002 11:17 AM
> To: lucene-user@jakarta.apache.org
> Subject: performing NOT queries
>
>
> Hi all,
>
> I'm relatively new to Lucene so this question may seem a little obvious
but
> I'm having some problems which may be a result of a misunderstanding on my
> part.
>
> A description of my problem is as follows:
>
> I have indexed 30 documents and then create a BooleanQuery as follows:
>
> BooleanQuery query = new BooleanQuery();
> query.add(QueryParser.parse("myValue", myFieldName, myAnalyzer), true,
> false);
>
> I then execute it against the indexes and receive 25 documents back.
>
> So I was to then execute the a boolean query constructed like:
>
> BooleanQuery query = new BooleanQuery();
> query.add(QueryParser.parse("myValue", mFieldName, myAnalyzer), true,
true);
>
> I _should_ get the other 5 right?
>
> Am I missing something here?
>
> Thanks in advance guys, you guys do awesome work.
>
> Regards,
>
> Minh Kama Yie
>
> This message is intended only for the named recipient.
> If you are not the intended recipient you are notified that
> disclosing, copying, distributing or taking any action
> in reliance on the contents of this information is strictly
> prohibited.
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: performing NOT queries

Posted by "Nader S. Henein" <ns...@bayt.net>.
in the Lucene JAVADOC you see this :
/*
public final void add(Query query,
                      boolean required,
                      boolean prohibited)Adds a clause to a boolean query.
Clauses may be:
required which means that documents which do not match this sub-query will
not match the boolean query;
prohibited which means that documents which do match this sub-query will not
match the boolean query; or
neither, in which case matched documents are neither prohibited from nor
required to match the sub-query.

It is an error to specify a clause as both required and prohibited.
*/

and you see that the last line states that "It is an error to specify a
clause as both required and prohibited."
so you can't so that, you need to think of these as on/off flags rather than
true and false from the boolean sense.

so in your second query try :

instead of this:

BooleanQuery query = new BooleanQuery();
query.add(QueryParser.parse("myValue", mFieldName, myAnalyzer), true, true)

try this:

BooleanQuery query = new BooleanQuery();
query.add(QueryParser.parse("myValue", mFieldName, myAnalyzer), false, true)

I hope this works, but by the way there are easier ways of doing a NOT,
check out the queryParser section of the JavaDocs

Nader Henein

-----Original Message-----
From: Minh Kama Yie [mailto:minh@nuix.com.au]
Sent: Thursday, August 08, 2002 11:17 AM
To: lucene-user@jakarta.apache.org
Subject: performing NOT queries


Hi all,

I'm relatively new to Lucene so this question may seem a little obvious but
I'm having some problems which may be a result of a misunderstanding on my
part.

A description of my problem is as follows:

I have indexed 30 documents and then create a BooleanQuery as follows:

BooleanQuery query = new BooleanQuery();
query.add(QueryParser.parse("myValue", myFieldName, myAnalyzer), true,
false);

I then execute it against the indexes and receive 25 documents back.

So I was to then execute the a boolean query constructed like:

BooleanQuery query = new BooleanQuery();
query.add(QueryParser.parse("myValue", mFieldName, myAnalyzer), true, true);

I _should_ get the other 5 right?

Am I missing something here?

Thanks in advance guys, you guys do awesome work.

Regards,

Minh Kama Yie

This message is intended only for the named recipient.
If you are not the intended recipient you are notified that
disclosing, copying, distributing or taking any action
in reliance on the contents of this information is strictly
prohibited.


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>