Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible in solr to specify an ordering of documents

Tags:

solr

Not a generic sort field, but say a list of document IDs I want returned in that order.

Example: document_ids = [5, 3, 10, 6]

Can I query solr for documents 5, 3, 10, 6 in that order?

like image 558
dalore Avatar asked Nov 06 '13 13:11

dalore


People also ask

What is boost in solr?

The “boost” parameter is very similar to the “bf” parameter, but instead of adding its result to the final score, it will multiply it. This is only available in the “Extended Dismax Query Parser” or the “Lucid Query Parser”.

What is DF in solr?

The df stands for default field , while the qf stands for query fields . The field defined by the df parameter is used when no fields are mentioned in the query. For example if you are running a query like q=solr and you have df=title the query itself will actually be title:solr .


1 Answers

Using Boost Query

You can use the bq param (Boost Query) for this and then sort by score, which is default.

q=id:5+OR+id:3+OR+id:10+OR+id:6&bq=id:5^4+id:3^3+id:10^2

As you can see within the bq parameter each of the IDs gets a declining boost value, until the last one - in your case 6 - does not receive any boost any more. Since you search by ID, each document would have the same score, so boosting them that way will get you the sort order you want.

Some reference about the parameter

  • bq (Boost Query) - Solr Wiki
  • The bq Parameter - Reference Guide

Using Term Boosting

In case you are using the Standard Request Handler or the (e)DisMax this works in any case

q=id:5^4+OR+id:3^3+OR+id:10^2+OR+id:6

This makes use of Term Boosting, which is explained in the reference documentation below the topic Boosting a Term with ^. The logic keeps the same as above.

like image 148
cheffe Avatar answered Sep 22 '22 15:09

cheffe