[英]Django + Haystack how to do this search
I'm new to Haystack and to the search world so I didn't know how to ask this question. 我是Haystack和搜索世界的新手,所以我不知道如何问这个问题。
What I want to achieve is the following. 我要实现的目标如下。
Having a search query like: one two 搜索查询如下:一二
I would like to get returned any content like: 我想得到任何类似的内容:
Is this possible with Haystack + solr/xapian? 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.
如果两个词都被击中,那将与我更加相关。
I'm currently using SearchQuerySet in my view but can't achieve that. 我目前在视图中使用SearchQuerySet,但无法实现。
Cheers 干杯
So you're basically looking for an OR
type query right? 因此,您基本上是在寻找
OR
类型查询吗? By default haystack uses an AND
operation for joining queries. 默认情况下,haystack使用
AND
操作联接查询。
You can do this two ways: 您可以通过两种方式执行此操作:
HAYSTACK_DEFAULT_OPERATOR
within your settings.py to be OR
. HAYSTACK_DEFAULT_OPERATOR
更改为OR
。 This will obviously be a site-wide change. SearchQuerySet
form to use filter_or which will force the OR
style lookup. SearchQuerySet
形式使用filter_or这将迫使OR
样式查找。 So pass a new one into your form/view: SearchQuerySet.filter_or(**kwargs)
SearchQuerySet.filter_or(**kwargs)
Apart from that, you could always join Django Q
objects together but considering you have these options, those are probably your best bet. 除此之外,您始终可以将Django
Q
对象连接在一起,但是考虑到您拥有这些选项,那么这些可能是您最好的选择。
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. 出于相关性,您应该阅读“ 最佳实践”页面,该页面涉及使用搜索模板,并使它们成为显示相关内容的方式。
Hope that helps! 希望有帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.