anand tiwari
anand tiwari

Reputation: 157

Solr: Excluding certain documents from getting sorted

I have a Solr query where i am trying to sort the results based on a certain field.

I want to modify it in such a way that only a particular set of documents get sorted and the remaining are simply appended to the end of the sorted list.

Is there a way to achieve this?

Please help.

Regards.

Upvotes: 0

Views: 381

Answers (2)

Jayendra
Jayendra

Reputation: 52769

If you want to Sort by a particular field condition which is dynamic, you can boost the field with matching condition higher and sort by score.
for e.g. bq=some_field:some_value^10
This will boost the scores of the documents only matching the criteria.
Also, for all the other documents the score would be unchanged and would follow the boasted documents as is.

EDIT :-
you can boost on multiple fields e.g. bq=string_array_field:some_value^10&bq=ranking^10 would boost the documents matching the value and the having higher ranking to the top.
The rest of the documents would follow.

Upvotes: 1

Paige Cook
Paige Cook

Reputation: 22555

For each <fieldType> definition in your schema.xml you can set a sortMissingLast="true" option that would give you the desired sorting behavior. For your specific example, I would recommend creating a new field with the sortMissingLast="true" set and use then populate this additional field based on your given criteria and not setting a value for those documents you want to appear at the end when sorted.

Upvotes: 0

Related Questions