使用 django-haystack,如何仅使用部分术语执行搜索?
我有 django.contrib.auth.models.User
的 Haystack/xapian 搜索索引。该模板只是
{{object.get_full_name}}
为了让用户输入名称并能够搜索它。
我的问题是这样的:如果我搜索,比如说,Sri
(我的全名),我会得到与我的名字相关的用户对象的结果。但是,如果我搜索 Sri Ragh
- 即我的全名和姓氏的一部分,我不会得到任何结果。
如何设置 Haystack 以便获得部分查询的适当结果? (我本质上希望它搜索*Sri Ragh*
,但我不知道通配符是否真的能做到这一点,或者如何实现它们)。
这是我的搜索查询:
results = SearchQuerySet().filter(content='Sri Ragh')
I've got a Haystack/xapian search index for django.contrib.auth.models.User
. The template is simply
{{object.get_full_name}}
as I intend for a user to type in a name and be able to search for it.
My issue is this: if I search, say, Sri
(my full first name) I come up with a result for the user object pertaining to my name. However, if I search Sri Ragh
- that is, my full name, and part of my last name, I get no results.
How can I set Haystack up so that I can get the appropriate results for partial queries?
(I essentially want it to search *Sri Ragh*
, but I don't know if wildcards would actually do the trick, or how to implement them).
This is my search query:
results = SearchQuerySet().filter(content='Sri Ragh')
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我曾经遇到过类似的问题,作为解决方法或者可能是修复,您可以更改查询查找
问题是 django-haystack 没有实现搜索引擎中的所有行话。当然你可以这样做。
正如 Django-haystack 所说,这是不可移植的。
I use to have a similar problem, as workaround or maybe a Fix you can change the query lookup
The issue is that django-haystack doesn't implement all lingos from search engines. Of course you can do this.
As Django-haystack says, this is not portable.
您可以使用 icontains 或startswith。
请小心这一点,例如,如果查询是“r”,这将为您带来内容中包含“r”的所有“模型”实体。
查看文档
You can use icontains or startswith.
Be careful with this one, if a query is for example 'r', this will bring you all 'Model' entities that have a 'r' in its content.
Look at the documentation