lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ian Lea <>
Subject Re: Using MultiField query with Boost factor
Date Fri, 07 Jun 2013 13:42:44 GMT
Take a look at BooleanQuery and the setBoost() call on Query, and
BooleanClause.Occur for the MUST/SHOULD logic.

Something along the lines of this pseudo code

BooleanQuery bq = new BooleanQuery();

Query titleq = xxx;
bq.add(titleq, must|should)

Query addressq = yyy
bq.add(addressq, ...), ...)

You might be able to do the whole thing with the query parser but once
the logic gets more than trivial I always prefer to build the queries
in code.  You can use the parser to generate the titleq, addressq etc.
queries if that is appropriate.

You can nest BooleanQuery instances if you need that level of if
(this) but not (that or that) unless (whichever or whatever) except
when ().  Which you might.


On Thu, Jun 6, 2013 at 7:05 AM, Abhishek Mallik
<> wrote:
> I have indexed documents in Lucene based on three fields: *title*, *address*
> , *city*. Now I want to build my query say, *C A B *so that I can retrieve
> the documents as follows:
> *C* must be present in the *title* field of the documents and either *A* or
> *B* must be present in either of *address* and *city *fields of the matched
> documents. The documents that have A present in either of those fields
> should get higher score or higher boost. Here *A*, *B*, *C* may be single
> terms or phrases.
> I am new to Lucene. I do not have any experience of framing such complex
> queries. So if anyone please help me to solve this I will be really
> grateful. Thank you.
> -Abhishek

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message