Sorting on text field in solr

user1556622 picture user1556622 · Apr 17, 2013 · Viewed 7.3k times · Source

I am using solr 3.4 and want to have solr search results to be sorted on text field. How can I achieve sorting on text field as with int natural ordering?

Is there any way to convert text field to int during query?

My sort field is of string type and I want it to be behave as int field while sorting. I can not change field type as the index size is too large and can not re index.

Any idea how can I achieve this?

Answer

Jayendra picture Jayendra · Apr 18, 2013

Not very sure, but you can check for the Function Queries with functions like abs or any mathematical functions which might convert it to the int values and use it for sort

e.g. abs(some_field) desc

Else, copy the field into the new field with int type which would need reindex.

Also, Sorting doesn't work good on multivalued and tokenized Text fields.

Documentation - Sorting can be done on the "score" of the document, or on any multiValued="false" indexed="true" field provided that field is either non-tokenized (ie: has no Analyzer) or uses an Analyzer that only produces a single Term (ie: uses the KeywordTokenizer)