Results ordered not by ranking

56 views
Skip to first unread message

Михаил Мишин

unread,
May 18, 2016, 3:50:43 AM5/18/16
to django-watson discussion group
Hello.
How to show search results ordered by some of model's field, not by ranking?
Thank you.

Jirka Vejrazka

unread,
May 18, 2016, 9:51:55 AM5/18/16
to django...@googlegroups.com
The watson.filter() and watson.search() functions supports ranking=False, so you get results ordered by their default ordering (as set in models.py). Also, .filter() returns normal QuerySet, so you can do your usual .order_by() on it.

 HTH

    Jirka



--
You received this message because you are subscribed to the Google Groups "django-watson discussion group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-watso...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-watson.
For more options, visit https://groups.google.com/d/optout.

Михаил Мишин

unread,
May 18, 2016, 10:16:24 AM5/18/16
to django-watson discussion group
I don't see any order in watson's SQL .search query, that is why i asking.

среда, 18 мая 2016 г., 10:50:43 UTC+3 пользователь Михаил Мишин написал:

Jirka Vejrazka

unread,
May 18, 2016, 3:22:37 PM5/18/16
to django...@googlegroups.com
Do you have "ordering" clause in your model.Meta or use explicit ordering on your search query?

  Jirka

Dave Hall

unread,
May 19, 2016, 9:48:16 AM5/19/16
to django...@googlegroups.com
If you use watson.search(), then the results are by default ordered by relevance. If you set ranking=False, then the result ordering is whatever is fastest for the database. Not very useful.

If you want to order by a field on a model, then use watson.filter(), which gives you a queryset of a single model, allowing you to use .order_by() to sort by a field. This only works when searching one particular model, and cannot do multi-model searches.

Ordering by a model-specific field using watson. search() is not supported.
Reply all
Reply to author
Forward
0 new messages