user1324887
user1324887

Reputation: 672

multiple condition sorting in solr

I have a sort which looks like

sort=score_dx desc, date_dt desc.

The problem is if there is a tie on first sort then the second sort applies to the whole record not only to the already sorted subsets.

for ex:

this is what I have from above sort

score_dx   date_dt 
0.1       2015/10/24

0.1       2015/10/23

0.9       2015/10/20

0.9       2015/10/19

what I want is

score_dx   date_dt 
0.9      2015/10/20

0.9      2015/10/19

0.1      2015/10/24

0.1      2015/10/23

The first sort result should not change and then the second sort whouls apply to within the subset.

How to do this in Solr?

Upvotes: 1

Views: 356

Answers (1)

MatsLindh
MatsLindh

Reputation: 52902

Since score_dx is a TrieLongField, the value will be cast to an integer (long is an integer with a broader range than what int has, 64 bits vs 32 bits), meaning that all the values you've indexed are, in fact, identical. Sorting by them will then give a order which seem random between them, and the only thing actually applying a sort will be the second criteria.

Change the field to a TrieDoubleField and reindex your content, and sort should work as you expect.

The reason why you're seeing 0.9 is that this is the stored value of the field, and not the actual value used for searching.

Upvotes: 1

Related Questions