2

Scenario is to boost documents on multiple field values:

I have a field "Category" containing values - "News", "image", "video", "audio".

Now on the basis of fields values mentioned above I would like to give some boosting(priority) to them, say for example "News" gets highest priority, followed by "video", than "audio" and so on.

Similar to category there are few more fields, which needed to boosted in the same manner based on fields values.

Ex. Boosting rules can be,

Category=  News^1000
Category=  Image^900
Premium_Contents = True^200
Sponsored = True^300

... so on

So I have came across a solution Reference. I am trying to find out the best approach for calculating my search relevancy result-sets.

GrafikRobot
  • 3,020
  • 1
  • 20
  • 21
Anumoy Sutradhar
  • 523
  • 5
  • 11

1 Answers1

3

Yes I think your link is a reasonable idea. It is what we use because we want to enforce are boosts on all searches and we don't change the logic very often, for example in your case:-

<requestHandler name="/select" class="solr.SearchHandler">
    <lst name="defaults">
        <str name="defType">edismax</str>
        <str name="boost">product(
                    map(query($type1query),0,0,1,$type1boost),
                    map(query($type2query),0,0,1,$type2boost))</str>
            <str name="type1query">Category:"News"</str>
            <double name="type1boost">1000.0</double>
            <str name="type2query">Category:"Image"</str>
            <double name="type2boost">900.0</double>
    </lst>
</requestHandler>

In this case the query function returns the score for the specific query. That is looking for match for News, Image etc in Category.

The map function has the following signature: map(x,min,max,target,value) maps any values of the function x that fall within min and max inclusive to target. min,max,target,value are constants. It outputs the field's value (or "value") if it does not fall between min and max. In other words if the result of query is a positive value (there is a match) it will output the boost (1000,900 etc). You'll need to play with the boost values as they can overwhelm any other ranking logic you have. You may get poor matches on News ranking first where there is a better match on Video, say.

You could create a separate request handler with these boosts so you can bypass them for other searches. Obviously you have to change solrconfig and restart Solr if you make any changes, which may be an issue.

Otherwise look at the bq (boost query) parameter.

bq=Category:News^1000.0+Category:Image^900...

which actually generates something like this under the covers

boost(+*:* (Category:News^1000 + Category:Image^900))

This means the boosts are done in your search code which is nice and flexible. Personally I prefer this way of working.

David George
  • 3,693
  • 1
  • 18
  • 22