lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Morus Walter <morus.wal...@tanto.de>
Subject Re: building a search query
Date Mon, 14 Jun 2004 06:29:45 GMT
Jeff Wong writes:

> 2) Also,  you should be wary of the possibility that your users may not know
> Boolean logic.  AND and OR may have different meanings for them.  For most
> people, AND is an inclusive operator and OR is basically XOR.  It may seem
> strange to you, but it's kind of like those optical illusions.  Is the
> picture of an old woman or a young lady?  Is that a wine glass or two people
> in profile?
> 
I don't think that this applies to search logic.
If you search for documents mentioning a picture of an old woman or a young 
lady you wouldn't want to exclude documents mentioning both.
> 
> To answer your question about using the BooleanQuery object,  you only need
> a single clause object to connect multiple terms.
> 
> To make a BooleanQuery like this:
> A OR B OR C
> 
> 
> q = new BooleanQuery()
> q.add( a, false, false)
> q.add( b, false, false)
> q.add( c, false, false)
> 
It's more complicated when you deal with different operators in a boolean 
query like A OR B AND C.
You cannot express that with a single BooleanQuery.

Usually AND has higher precedence in which case this can be expressed as
q = new BooleanQuery()
q.add( a, false, false );
q2 = new BooleanQuery();
q2.add(b, true, false);
q2.add(c, true, false);
q.add( q2, false, false );

If you'd add required terms to q directly you would end up, with a query
searching for B AND C only, where documents containing A get a better score.

So for the initial question, I'd suggest:

you cannot simply create a list of terms and operators, you need to build
a query tree that expresses the precedence of the operations.
Then you will have groups of term queries that are either OR- or AND- 
(including AND NOT) combined, which can easily be converted to an apropriate
BooleanQuery.

Morus

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


Mime
View raw message