Order solr documents with same score by date added descending

Dorin picture Dorin · Feb 10, 2012 · Viewed 9.3k times · Source

I want to have search results from SOLR ordered like this:

All the documents that have the same score will be ordered descending by date added.

So when I query solr I will have n documents. In this results set there will be groups of documents with the same score. I want each of this group of documents to be ordered descending by date added.

I discovered I can accomplish this using function queries, more exactly using rord function http://wiki.apache.org/solr/FunctionQuery#rord, but as it is stated in the documentation

WARNING: as of Solr 1.4, ord() and rord() can cause excess memory use since they must use a FieldCache entry at the top level reader, while sorting and function queries now use entries at the segment level. Hence sorting or using a different function query, in addition to ord()/rord() will double memory use.

it will cause excess memory use.

What other options do I have ?

I was thinking to use recip(ms(NOW,startTime),1,1,0). Is this the best approach ?

Is there any negative performance impact if I use recip and ms ?

Answer

Stelian Matei picture Stelian Matei · Feb 10, 2012

You can use multiple SORT conditions:

Multiple sort orderings can be separated by a comma, ie: sort=+[,+]...

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

So, in your case would be: sort=score DESC, date_added DESC