简体   繁体   English

如何在Django中使用干草堆实现通配符搜索

[英]How to achieve wildcard search using haystack in django

I am currently working on haystack search in django. 我目前正在django进行干草堆搜索。 I met 2 problems, first, when I use 'Whoosh' engine, the search can only return the result that match exactly the same with my search key, for example if I type 'ABC', it cannot match 'ABCD' Secondly, how can I achieve wildcard search using haystack? 我遇到了两个问题,首先,当我使用“ Whoosh”引擎时,搜索只能返回与我的搜索键完全匹配的结果,例如,如果键入“ ABC”,则不能匹配“ ABCD”;其次,如何如何使用干草堆实现通配符搜索? For example, if I type'A*C', it can return 'ABC', 'ABCCC' 'AC' and so one. 例如,如果键入“ A * C”,则可以返回“ ABC”,“ ABCCC”,“ AC”等。 Or other method just to achieve the same result(Basically, return the result that contains the key word in same order) 或其他仅用于获得相同结果的方法(基本上,以相同顺序返回包含关键字的结果)

Please note that there are a few considerations when using wildcards. 请注意,使用通配符时有一些注意事项。 First, there are some things to consider with Haystack, check the suggestion here . 首先,Haystack需要考虑一些事项,在此处查看建议。 Wildcards work by default with auto_search, otherwise you'll have to compile the query yourself. 默认情况下,通配符与auto_search一起使用,否则,您必须自己编译查询。

On the other hand, you must consider the back end haystack uses. 另一方面,您必须考虑后端干草堆的用途。 I haven't used Whoosh recently, but I know that other back ends, like Solr, for example, uses by default a minimum of 3 character 'groups' when generating search items, so it may also be the case that the search you are doing does not fall into any of those groups, or it won't match words with fewer than 3 chars. 我最近没有使用过Whoosh,但是我知道其他后端(例如Solr)在生成搜索项时默认使用至少3个字符的“组”,因此也可能是您正在搜索这样做不会属于任何这些组,或者不会匹配少于3个字符的单词。

Depending on the back end you may also configure if the search you want is a 'starts with', 'contains', 'ends with'. 根据后端,您还可以配置所需的搜索是“开始于”,“包含”还是“结束于”。 You may also need to look into Whoosh documentation for this. 您可能还需要查看Whoosh文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM