简体   繁体   中英

How to achieve wildcard search using haystack in django

I am currently working on haystack search in 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? For example, if I type'A*C', it can return 'ABC', 'ABCCC' 'AC' and so one. 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 . Wildcards work by default with auto_search, otherwise you'll have to compile the query yourself.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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