简体   繁体   English

一个很好的django搜索应用程序? - 如何使用Haystack进行模糊搜索?

[英]A good django search app? — How to perform fuzzy search with Haystack?

I'm using django-haystack at the moment with apache-solr as the backend. 我现在正在使用django-haystack和apache-solr作为后端。

Problem is I cannot get the app to perform the search functionality I'm looking for 问题是我无法让应用程序执行我正在寻找的搜索功能

  1. Searching for sub-parts in a word 搜索单词中的子部分

    eg. 例如。 Searching for "buntu" does not give me "ubuntu" 搜索“buntu”不会给我“ubuntu”

  2. Searching for similar words 寻找类似的单词

    eg. 例如。 Searching for "ubantu" would give "ubuntu" 搜索“ubantu”会给“ubuntu”


Any help would be very much appreciated. 任何帮助将非常感谢。

This is really about how you pass the query back to Haystack (and therefore to Solr). 这实际上是关于如何将查询传递回Haystack(因此也传递给Solr)。 You can do a 'fuzzy' search in Solr/Lucene by using a ~ after the word: 您可以在Solr / Lucene中使用~后面的'模糊'搜索:

ubuntu~

would return both buntu and ubantu . 将返回buntuubantu See the Lucene documentation on this. 请参阅Lucene文档

How you pass this through via Haystack depends on how you're using it at the moment. 你如何通过Haystack传递这个取决于你现在如何使用它。 Assuming you're using the default SearchForm, the best thing would be to either override the form's clean_q method to add the tilde on the end of every word in the search results, or override the search method to do the same thing there before passing it to the SearchQuerySet. 假设您正在使用默认的SearchForm,最好的方法是覆盖表单的clean_q方法,在搜索结果中的每个单词的末尾添加波浪号,或者在传递之前覆盖search方法以执行相同的操作到SearchQuerySet。

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

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