Reputation: 51
In my application, I have a solr string field which can contain values like A1, A2, A10, A100.
If I apply sort function in that field I am getting the result as A1, A10, A100, A2. But my intention is to get the sorting as natural number way like A1, A2, A10, A100 excluding the char part for my indexed value. Is there any way to do that?
Upvotes: 2
Views: 1283
Reputation: 236
Or you introduce a new fieldtype and introduce a new comparator for that one, as described in this approach: http://sujitpal.blogspot.com/2011/05/custom-sorting-in-solr-using-external.html (their use-case is a bit more complex, but the main logic with defining a field type, using a custom FieldComparatorSource in there providing a comparator should work for your case). Within the comparator you could then sort for length and then for value first or add some logic to distinguish the parts of the strings before sorting on them.
Upvotes: 2