Below snippet will help you to sort solr search results.
Few things i would like to highlight about solr result sorting.
You can not sort tokenized field i mean if you have defined your solr field with the type text or textToTight.
You can sort the field which have type string . You can create dynamic fields easily in solr.
Add below entry in schema.xml and solr will automatically create field with the type string.
<dynamicField name="*_sortable" type="string" indexed="true" multiValued="false" stored="true" />
If you use any field with suffix _sortable then solr will automatically create field if it is not exist.
Few things i would like to highlight about solr result sorting.
You can not sort tokenized field i mean if you have defined your solr field with the type text or textToTight.
You can sort the field which have type string . You can create dynamic fields easily in solr.
Add below entry in schema.xml and solr will automatically create field with the type string.
<dynamicField name="*_sortable" type="string" indexed="true" multiValued="false" stored="true" />
If you use any field with suffix _sortable then solr will automatically create field if it is not exist.
I have used this code ans still solr is not hitting with sorted field what I passed in search Context.
ReplyDeletePlease note my code as below,
http://stackoverflow.com/questions/33547609/set-order-in-solr-query-with-searchcontext-liferay