如何使Wagtail搜索不区分大小写

时间:2016-07-27 20:08:40

标签: python django search elasticsearch wagtail

我使用Wagtail serach:

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')
]

但它区分大小写。因此,查询howHow会产生不同的结果。

我需要以这种方式进行搜索:

当我输入howHow时,它应该返回

how to...
How to...
The way how...
THE WAY HoW...

换句话说,它应该在所有可能的案例中找到how的所有提及。

如何让它发挥作用?

P.S。:我正在使用默认后端,如果需要,我可以自由更改。

1 个答案:

答案 0 :(得分:3)

使用Wagtail的弹性搜索后端,使用#include <boost/asio.hpp> int main() { boost::asio::io_service io; boost::asio::io_service::work io_work(io); boost::asio::io_service::strand strand1(io); boost::asio::io_service::strand strand2(io); int val = 0; strand1.post([&val, &strand2]() { val = 1; strand2.post([&val]() { val = 2; }); boost::asio::spawn(strand2, [&val](boost::asio::yield_context yield) { val = 3; }); }); io.poll_one(); std::cout << "Last executed: " << val << std::endl; return 0; } 索引的字段在lowercase中被标记化。因此,要完成不区分大小写的搜索,您需要做的就是小写查询字符串:

partial_match=True
相关问题