使用django-haystack,如何按内容类型排序结果 [英] Using django-haystack, how do I order results by content type

查看:1008
本文介绍了使用django-haystack,如何按内容类型排序结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的网站上使用django-haystack作为搜索页面,我想按照其内容类型对所有结果进行排序。有办法可以做到吗?
为了更简单,假设我有一个应用程序和几个类。
提前感谢

I'm using django-haystack for a search page on my site, and I want to order all the results by their content type. Is there a way I can do that? To make it simpler, suppose I have a single application and several classes. Thanks in advance

推荐答案

如何按模型订购搜索结果


您可以执行
SearchQuerySet()。order_by('django_ct')
作为警告,这抛出
相关性。保持
相关性&按模型分组是
运行许多查询(每个模型一个 -
通常执行查询
缓存)或运行查询和
后处理结果,重新组合
他们当你走。

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.

searchindex api


Haystack保留以下字段
名称用于内部使用:id,django_ct,
django_id&内容。名称&键入
名称以前被保留,但没有
更长。

Haystack reserves the following field names for internal use: id, django_ct, django_id & content. The name & type names used to be reserved but no longer are.

您可以使用HAYSTACK_ID_FIELD,$ b覆盖这些字段名称
$ b HAYSTACK_DJANGO_CT_FIELD&
HAYSTACK_DJANGO_ID_FIELD(如果需要)

You can override these field names using the HAYSTACK_ID_FIELD, HAYSTACK_DJANGO_CT_FIELD & HAYSTACK_DJANGO_ID_FIELD if needed.

这篇关于使用django-haystack,如何按内容类型排序结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆