How to sort?
I can search by field like /search?is_approved=true&is_active=true
However, I need a way to sort the result by a field e.g. /search?is_approved=true&is_active=true&order=[-date]
How to achieve this?
Will be looking into this myself in the near future. But could you pass a form_class in your view similar to how it would be achieved with a standard haystack view?
http://www.django-rest-framework.org/api-guide/filtering/#orderingfilter you could try this, it does work!
@rhblind I'm testing the ordering and it is not working with char fields. Do I have to do anything different when indexing char fields?
@rodrigowirth What backend do you use? I've done some testing on this with Elasticsearch backend and for me it "somewhat" works. The reason is that Elasticsearch (or any other backend for that matter) does ordering slightly differently. I've not fully managed to understand how this works, but in practice any ordering passed are just passed directly to SearchQueryset().order_by(*args) and from there it's up to the backend to order the dataset by its own rules. In my tests I've also tried ordering by char fields and gotten unexpected results.
Unfortunately I don't have any better answer other than that I'd also like to have this feature working, but haven't had time to look too deeply into it yet. 😕
sorting is not working for the fields of type long in solr. I am using django-haystack library. URL: localhost:8000/searchManagement/search/t/?age_group_to__gte=35&sort=age_group_from asc