Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Solr Boost on non-query term

Tags:

solr

edismax

All my results are of type "active, inactive, historical" - this is a field indexed by Solr.

I want my results to be returned with a boost to type="active".

I could do ordering which will suffice, but its not great.

So, when a user searches for a term "sick", they get the most relevant results to sick, but with a higher boost for documents where its active.

Not just a sorted result set!

like image 909
Mark Avatar asked Jan 18 '23 03:01

Mark


2 Answers

You can use the edismax parser and the following boost query bq paramter to get your desired results to be boosted to the top...

 http://localhost:8983/solr/select/?q=sick&defType=edismax&bq=type:active^5.0

In this example you are adding a boost query to increase the relevancy of documents whose type is active.

Here are some more examples on the Solr Wiki DisMaxQParserPlugin page.

like image 113
Paige Cook Avatar answered Feb 24 '23 12:02

Paige Cook


The above example will create an additive boost. If you want an multiplicative boost for "type=active" you could add:

&boost=if(termfreq(type,"active"),2,1)

Which gives a factor 2 boost for "type=active"

like image 21
kraftb Avatar answered Feb 24 '23 14:02

kraftb