[英]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.