【发布时间】:2012-05-21 03:33:24
【问题描述】:
我有一个自动完成框,它需要返回包含输入单词的结果。但是,输入的单词可以是部分的,并且可以位于不同的顺序或位置。
示例:
数据库列(MySQL)中的值-
Expected quarterly sales
Sales preceding quarter
Profit preceding quarter
Sales 12 months
现在如果用户输入quarter sales,那么它应该返回前两个结果。
我试过了:
column__icontains = term #searches only '%quarter sales% and thus gives no results
column__search = term #searches any of complete words and also returns last result
**{'ratio_name__icontains':each_term for each_term in term.split()} #this searches only sales as it is the last keyword argument
任何通过正则表达式的技巧或者可能是我在 Django 中缺少的东西,因为这是一种常见的模式?
【问题讨论】:
-
也许我弄错了,但这对我来说更像是一个全文搜索问题。你应该看看 MySQL 全文搜索,看看它是否符合你的需要。
-
您是否尝试过使用任何搜索引擎?检查干草堆(haystacksearch.org)。它支持在开始时非常容易使用的嗖嗖声,还有更多
-
嗨 Manoj,我确实尝试了全文搜索,但它返回的结果包含上述任何单词。例如,它还返回 12 个月的销售额(它不应该)。