lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jay Joel Malaluan <exst_jmalal...@yahoo.com>
Subject Re: Unique results in BooleanQuery
Date Wed, 17 Dec 2008 06:57:42 GMT
Let me expound more on the question. Will the q1 be run on the BooleanQuery q2 and append the
results that are not equal to the result of the first query of q2?




________________________________
From: Jay Joel Malaluan <exst_jmalaluan@yahoo.com>
To: java-user@lucene.apache.org
Sent: Wednesday, December 17, 2008 2:42:06 PM
Subject: Re: Unique results in BooleanQuery

Hi Paul,

But will the q1 be run on the BooleanQuery q2 or q1 is just used for filtering?  


Regards,
Jay Malaluan





________________________________
From: Paul Cowan <cowan@aconex.com>
To: java-user@lucene.apache.org
Sent: Wednesday, December 17, 2008 1:37:15 PM
Subject: Re: Unique results in BooleanQuery

Hi Jay,

> Anyone knowledgeable on how to get unique hits using the BooleanQuery?
> If I have 2 queries so the when the 1st query is processed then the 2nd
> query will not anymore return the same results from the 1st query. 

Do you mean you want to run two separate queries -- get all the results from query 1 first,
then get the results which match query 2 but also DON'T match query 1?

e.g. search for "fruit:apple", get back x records
then search for "colour:blue", get back records with 'blue' as a colour but WITHOUT 'apple'
as a fruit?

Do the first query as normal, then create a second BooleanQuery; add one clause for "colour:blue",
Occur.MUST, and then add the query from the first search as a MUST_NOT.

Query q1 = new TermQuery(new Term("fruit", "apple"));
..... run query, get back all apples ...

BooleanQuery q2 = new BooleanQuery();
q2.add(new TermQuery(new Term("colour", "blue")), Occur.MUST);
q2.add(q1, Occur.MUST_NOT);
..... run query q2, get back all blue things that don't have apples ...

Cheers,

Paul

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


      
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message