Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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"

  2. Searching for similar words

    eg. Searching for "ubantu" would give "ubuntu"


Any help would be very much appreciated.

like image 963
RadiantHex Avatar asked Jan 23 '23 17:01

RadiantHex


1 Answers

This is really about how you pass the query back to Haystack (and therefore to Solr). You can do a 'fuzzy' search in Solr/Lucene by using a ~ after the word:

ubuntu~

would return both buntu and ubantu. See the Lucene documentation on this.

How you pass this through via Haystack depends on how you're using it at the moment. 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.

like image 63
Daniel Roseman Avatar answered Jan 25 '23 05:01

Daniel Roseman