lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ian Lea <ian....@gmail.com>
Subject Re: Using MultiField query with Boost factor
Date Fri, 07 Jun 2013 15:28:26 GMT
Phrases or otherwise should be irrelevant other than titleq or
addressq will be PhraseQuery or TermQuery or whatever.

To get "A or B in either city or address", in my suggested solution,
you'd need a BooleanQuery something like

BooleanQuery bq = new BooleanQuery()
Query caq = new whatever("A in city")
Query cbq = new whatever("B in city")
Query aaq = new whatever("A in address")
Query abq = new whatever("B in address")
bq.add(caq, should)
bq.add(cbq, should)
bq.add(aaq, should)
bq.add(abq, should)

And, if necessary, add this bq to another one along with your query on
title. Boosting as you go.


Alternatives might include MultiFieldQueryParser or adding a new
city-and-address field.


--
Ian.


On Fri, Jun 7, 2013 at 3:48 PM, Abhishek Mallik
<abhishek.mallik.cs@gmail.com> wrote:
> I understand but how to handle the situation where A or B may be phrase and
> present in both the fields.
>
>
> On Fri, Jun 7, 2013 at 7:12 PM, Ian Lea <ian.lea@gmail.com> wrote:
>
>> 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;
>> titleq.setBoost(somevalue)
>> bq.add(titleq, must|should)
>>
>> Query addressq = yyy
>> addressq.setBoost(someothervalue)
>> bq.add(addressq, ...)
>>
>> searcher.search(bq, ...)
>>
>>
>> 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.
>>
>>
>> --
>> Ian.
>>
>>
>>
>> On Thu, Jun 6, 2013 at 7:05 AM, Abhishek Mallik
>> <abhishek.mallik.cs@gmail.com> 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: java-user-unsubscribe@lucene.apache.org
>> For additional commands, e-mail: java-user-help@lucene.apache.org
>>
>>

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


Mime
View raw message