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?
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)
It is not possible to do it during the query.
You have to had additional field and copying the text field over the new integer field, then reindex your database.
Use a filter to be sure that the conversion will work.