How to order search results by Model

510 views
Skip to first unread message

zweb

unread,
Jun 29, 2010, 12:56:29 PM6/29/10
to django-haystack
How can I order search results by model?

Greg Brown

unread,
Jun 29, 2010, 6:50:40 PM6/29/10
to django-...@googlegroups.com
This might depend on the backend, but I've had problems trying to
order and filter on that sort of thing - I had to store the model name
explicitly in the index, in a charfield.

Daniel may have a better way though!

Greg

On 30 June 2010 04:56, zweb <trader...@gmail.com> wrote:
> How can I order search results by model?
>

> --
> You received this message because you are subscribed to the Google Groups "django-haystack" group.
> To post to this group, send email to django-...@googlegroups.com.
> To unsubscribe from this group, send email to django-haysta...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/django-haystack?hl=en.
>
>

--
http://gregbrown.co.nz/

Daniel Lindsley

unread,
Jul 20, 2010, 1:53:03 AM7/20/10
to django-...@googlegroups.com
zweb,


You can do ``SearchQuerySet().order_by('django_ct')``. As a
warning, this throws out relevancy. The only way to keep relevancy &
group by model is either to run many queries (one per model - usually
performant thanks to query caching) or to run the query and
post-process the results, regrouping them as you go.


Daniel

Sid

unread,
Jul 26, 2010, 2:36:42 AM7/26/10
to django-haystack
Supposing one does do multiple queries, one per model. How would one
merge the two resultant query sets, since they might need to be
paginated?

Not sure if queryset chain is the best way to go, http://djangosnippets.org/snippets/1103/
Any thoughts?

-Sid
http://sidmitra.com

Reply all
Reply to author
Forward
0 new messages