如何在Haystack中仅返回特定类型的索引对象 [英] How to return only indexed objects of a specific type in Haystack

查看:233
本文介绍了如何在Haystack中仅返回特定类型的索引对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法使用SearchQuerySet并将结果限制在特定的索引模型? ie如果我添加了Note和NoteIndex到Haystack,我可以拉出对应于Note实例的结果?



编辑:


$ b $我已经看了一下,发现有一个名为django_ct的保留字段存储在每个索引模型上。是否可以过滤此字段?什么价值观?



双重编辑:



Nevermind。阅读Haystack源代码后,django_ct在内部是'appname.modelname',可以通过SearchQuerySet.filter(django_ct ='appname.modelname')查询

解决方案

根据Haystack文档,SearchQueryset对象有一个名为models()的方法,将结果限制为这些模型。



例如

  SearchQuerySet()。models(BlogEntry,Comment).filter(content ='foo')

如您所见,它使用实际的模型类。我的猜测是它使用它来查找内容类型来执行过滤器。


Is there any way to use SearchQuerySet and restrict the results to only a specific indexed model? i.e. If i add Note and NoteIndex to Haystack, can I pull out just results that correspond to Note instances?

EDIT:

I have had a look and found that there is a reserved field named django_ct that is stored on every indexed model. Is it possible to filter on this field? What values does it take?

DOUBLE EDIT:

Nevermind. After reading the Haystack source code, django_ct is 'appname.modelname' internally and can be querired with SearchQuerySet.filter(django_ct = 'appname.modelname')

解决方案

According to the Haystack documentation, a SearchQueryset object has a method called models() that restricts the results to those models.

e.g.

SearchQuerySet().models(BlogEntry, Comment).filter(content='foo')

As you see, it uses the actual model class. My guess is that it uses this to lookup the content-type to perform filter.

这篇关于如何在Haystack中仅返回特定类型的索引对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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