Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to sort? #106

Open
alreadysabbir opened this issue Jul 26, 2017 · 5 comments
Open

How to sort? #106

alreadysabbir opened this issue Jul 26, 2017 · 5 comments

Comments

@alreadysabbir
Copy link

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?

@wilkinj33
Copy link

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?

@Mr-win7
Copy link

Mr-win7 commented Jun 17, 2018

http://www.django-rest-framework.org/api-guide/filtering/#orderingfilter
you could try this, it does work!

rhblind added a commit that referenced this issue Jun 18, 2018
@rodrigowirth
Copy link

@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?

@rhblind
Copy link
Owner

rhblind commented Sep 28, 2018

@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. 😕

@suthugotyolo
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants