[英]How to make Wagtail search case-insensitive
我用Wa尾ser
query = self.request.query_params
questions = models.Questions.objects.filter(
answer__isnull=False,
owner__isnull=False).exclude(answer__exact='')
s = get_search_backend()
results = s.search(query[u'question'], questions)
这就是我为Questions
模型建立索引的方式:
search_fields = [
index.SearchField('question', partial_match=True, boost=2),
index.FilterField('answer'),
index.FilterField('owner_id')
]
但它区分大小写。 因此,查询how
以及How
将给出不同的结果。
我需要使搜索行为如下:
当我输入how
或How
,它应该返回
how to...
How to...
The way how...
THE WAY HoW...
换句话说,它应该找到所有的提到了how
在所有的情况下,更多钞票。
我该如何运作?
PS:我使用的是默认后端,可以根据需要随意更改。
使用Wagtail的elasticsearch后端,将标为partial_match=True
字段标记为小写 。 因此,要完成不区分大小写的搜索,您需要做的就是小写查询字符串:
results = s.search(query[u'question'].lower(), questions)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.