We have some documents which are indexed with a date d1
on some of the documents and d2
on others, and we want to sort on both of them depending which one os available.
sort=d1 desc, d2 desc
will sort the document with d1
seperatly for the document with d2
, like this:
d1: 2014-03-12
d1: 2010-03-12
d2: 2013-03-12
d2: 2011-03-12
What we want is everything sorted like this:
d1: 2014-03-12
d2: 2013-03-12
d2: 2011-03-12
d1: 2010-03-12
Reindexing all documents with a new common field is not an option unfortunately.
As much i know, you can use Function Queries of solr. For this sort, it is something like that
sort=if((abs(ms(d1,d2)) > 0),d1,d2) desc
I have not tested it yet, but here is the helpful link which will sort out your problem.
https://wiki.apache.org/solr/FunctionQuery
Sort result by date difference
The approach of Abdul to use a function is the correct approach. But the solution of Abdul does not work for me.
I've successfully tested this.
Just add this parameter to your query:
sort=max(d1,d2) desc
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With