You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Mark Cornick <ma...@viget.com> on 2008/01/18 23:43:00 UTC

Short-circuiting OR

Greetings,

We're working on an application for a client that uses Solr (via the  
acts_as_solr Rails plugin) to query a database of about 16 million  
business listings. Part of our client's strategy is to weigh matches  
on certain fields higher than others. We've been using Solr boosts to  
accomplish this. However, what they want is for only the match with  
the highest boost to figure into the relevancy. What we tried to do  
was a query something like

(field_a:Food^40 OR field_b:Food^30 OR field_c:Food^20 OR  
field_d:Food^10)

but from reading debugQuery output, assuming we search for "food", all  
four fields are matching and boosting the relevancy appropriately.  
What we need is a sort of short-circuiting OR operator; that is, once  
it matches one of the fields (in this case, field_a) it will stop  
evaluating everything else inside the parenthesized group and boost  
only by that first field (in this case, only the boost of 40.)

 From my reading of Solr and Lucene documentation, it doesn't appear  
obvious that there's a way to do this. Has anyone ever tried to do  
something like this? If so, how did you do it? Thanks in advance for  
any help.


Mark Cornick, Web Developer/System Administrator, Viget Labs
mark.cornick@viget.com
http://www.viget.com/

Re: Short-circuiting OR

Posted by Mike Klaas <mi...@gmail.com>.
Unfortunately, dismax does not do short-circuiting in the computer  
science sense (stop evaluation once one clause matches).

I too have thought about implementing a scorer that has that  
behaviour, but I've never gotten around to it (it would be expensive).

-Mike

On 18-Jan-08, at 3:13 PM, Yonik Seeley wrote:

> See DisMax... it will let you easily do multi-field queries that do
> what you want.
>
> http://wiki.apache.org/solr/DisMaxRequestHandler
>
> q=food&qf=field_a^40 field_b^30 field_c^20 field_d^10
>
> -Yonik
>
> On Jan 18, 2008 5:43 PM, Mark Cornick <ma...@viget.com> wrote:
>> Greetings,
>>
>> We're working on an application for a client that uses Solr (via the
>> acts_as_solr Rails plugin) to query a database of about 16 million
>> business listings. Part of our client's strategy is to weigh matches
>> on certain fields higher than others. We've been using Solr boosts to
>> accomplish this. However, what they want is for only the match with
>> the highest boost to figure into the relevancy. What we tried to do
>> was a query something like
>>
>> (field_a:Food^40 OR field_b:Food^30 OR field_c:Food^20 OR
>> field_d:Food^10)
>>
>> but from reading debugQuery output, assuming we search for "food",  
>> all
>> four fields are matching and boosting the relevancy appropriately.
>> What we need is a sort of short-circuiting OR operator; that is, once
>> it matches one of the fields (in this case, field_a) it will stop
>> evaluating everything else inside the parenthesized group and boost
>> only by that first field (in this case, only the boost of 40.)
>>
>>  From my reading of Solr and Lucene documentation, it doesn't appear
>> obvious that there's a way to do this. Has anyone ever tried to do
>> something like this? If so, how did you do it? Thanks in advance for
>> any help.
>>
>>
>> Mark Cornick, Web Developer/System Administrator, Viget Labs
>> mark.cornick@viget.com
>> http://www.viget.com/
>>


Re: Short-circuiting OR

Posted by Yonik Seeley <yo...@apache.org>.
See DisMax... it will let you easily do multi-field queries that do
what you want.

http://wiki.apache.org/solr/DisMaxRequestHandler

q=food&qf=field_a^40 field_b^30 field_c^20 field_d^10

-Yonik

On Jan 18, 2008 5:43 PM, Mark Cornick <ma...@viget.com> wrote:
> Greetings,
>
> We're working on an application for a client that uses Solr (via the
> acts_as_solr Rails plugin) to query a database of about 16 million
> business listings. Part of our client's strategy is to weigh matches
> on certain fields higher than others. We've been using Solr boosts to
> accomplish this. However, what they want is for only the match with
> the highest boost to figure into the relevancy. What we tried to do
> was a query something like
>
> (field_a:Food^40 OR field_b:Food^30 OR field_c:Food^20 OR
> field_d:Food^10)
>
> but from reading debugQuery output, assuming we search for "food", all
> four fields are matching and boosting the relevancy appropriately.
> What we need is a sort of short-circuiting OR operator; that is, once
> it matches one of the fields (in this case, field_a) it will stop
> evaluating everything else inside the parenthesized group and boost
> only by that first field (in this case, only the boost of 40.)
>
>  From my reading of Solr and Lucene documentation, it doesn't appear
> obvious that there's a way to do this. Has anyone ever tried to do
> something like this? If so, how did you do it? Thanks in advance for
> any help.
>
>
> Mark Cornick, Web Developer/System Administrator, Viget Labs
> mark.cornick@viget.com
> http://www.viget.com/
>