Django + Haystack如何执行此搜索 [英] Django + Haystack how to do this search
问题描述
我是Haystack和搜索世界的新手,所以我不知道如何问这个问题。
I'm new to Haystack and to the search world so I didn't know how to ask this question.
我要实现的目标如下。
What I want to achieve is the following.
具有一个搜索查询,例如:一两个
Having a search query like: one two
我想返回以下任何内容:
I would like to get returned any content like:
- 这一个
- 一个
- 两个
- 两个一个
- 这里有一个东西
- This one
- one
- two
- two one
- something one here
这可能与干草堆+ Solr / Xapian?
还可能与结果相关吗?在两个单词都被击中的情况下,这将给我更多的相关性。
Is this possible with Haystack + solr/xapian? Is also possible to have a relevance on the result? In the case where both words are hit, that would give more relevance to me.
我目前在视图中使用SearchQuerySet,但无法实现。
I'm currently using SearchQuerySet in my view but can't achieve that.
干杯
推荐答案
所以,您基本上是在寻找 OR
类型查询对吗?默认情况下,haystack使用 AND
操作来加入查询。
So you're basically looking for an OR
type query right? By default haystack uses an AND
operation for joining queries.
您可以通过以下两种方式进行操作:
You can do this two ways:
- 在您的settings.py中将
HAYSTACK_DEFAULT_OPERATOR
更改为OR
。显然,这将是整个站点范围的更改。 - 修改您的
SearchQuerySet
表单以使用 filter_or 这将强制使用OR
样式抬头。因此,将一个新值传递到您的表单/视图中:SearchQuerySet.filter_or(** kwargs)
- Change
HAYSTACK_DEFAULT_OPERATOR
within your settings.py to beOR
. This will obviously be a site-wide change. - Modify your
SearchQuerySet
form to use filter_or which will force theOR
style lookup. So pass a new one into your form/view:SearchQuerySet.filter_or(**kwargs)
除此之外,您总是可以将Django Q
对象连接在一起,但是考虑到您有这些选择,那可能是最好的选择。
Apart from that, you could always join Django Q
objects together but considering you have these options, those are probably your best bet.
相关性,您应该阅读最佳做法页面,该页面将使用搜索模板并使它们成为显示相关内容的方式。
For relevance, you should read the Best Practices page which goes into using search templates and making them be your way to show relevant content.
希望有帮助!
这篇关于Django + Haystack如何执行此搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!