Sorting on multiple fields


(Mark Evans) #1

Im attempting to do a sort on multiple fields... if a user chooses to search on date then i sort by date alone...

however for the default (relevance) search i want the sort order to be score descending then date descending if scores are the same for 2 or more results....

but not sure my code is working correctly, the else clause seems to be sorting on score only... when 2 or more scores are the same, the dates are not sorting in descending order, the date descending doesnt seem to take effect

my code is

.Sort(srt =>
    {
        if (m_intOrderBy == 0) { return srt.OnField(t => t.ESDateOrderedBy).Descending(); }
        else { return srt.OnField("_score").Descending().OnField(f => f.ESDateOrderedBy).Descending(); }

(system) #2