So I want to sort my Solr response by the following fields:
Problem is that status_color
must be sorted by the following values (e.i. not alphabetically):
This field may only contain one of these values.
I'm hoping theres a way of doing this in the Solr query instead of massaging the result in code. With a result of hundreds of thounsands of documents it's not really an option.
Any help is appreciated.
As the sort order field isn't returned by default the best way to handle this is to add a add a new computed field to the index. This will then be available to query by in Solr. 1. Computed Index Field
A sort ordering must include a field name (or score as a pseudo field), followed by whitespace (escaped as + or %20 in URL strings), followed by a sort direction ( asc or desc ). Multiple sort orderings can be separated by a comma, using this syntax: sort=<field name><direction>,<field name><direction>],…
You can use CASE to specify a sort key in the ORDER BY clause, which is exactly what we’re doing here. We give the first case a sorting key value of 1: This ensures that the results of the first case will be shown ahead of our second case. The last data we want to be displayed is where the order count is above 20.
You can use the rows parameter to paginate results from a query. The parameter specifies the maximum number of documents from the complete result set that Solr should return to the client at one time. The default value is 10. That is, by default, Solr returns 10 documents at a time in response to a query.
I think the answer for this question will be valid for you too:
Is it possible in solr to specify an ordering of documents
I believe Solr has Enum types, though I have never seen them used in a while. But they would be a perfect match, so worth a try.
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