Please format your code using </>
icon as explained in this guide. It will make your post more readable.
Or use markdown style like:
```
CODE
```
but the sort does not return a correct order.
What does it return? Why do you think it's not the correct order? What would you expect?
Could you provide a full recreation script as described in
It will help to better understand what you are doing.
Please, try to keep the example as simple as possible.
Anyway, it's often a question of analyzers. You can analyze the same text for different purposes with subfields (aka multifields) and use one method for searching and the other for sorting.