I think that while sqlite is an amazing piece of software, full-text search capabilities are very limited. Instead, you can index your database using the Haystack Django app with some backends, such as Elasticsearch . Having this setup (and still available for your sqlite database) seems to me to be the most reliable and flexible way in terms of FTS.
Elasticsearch has a fuzzy search based on Levenshtein distance (in a nutshell it will handle your "egsample" requests). So, all you need to do is make the correct request type:
from haystack.forms import SearchForm from haystack.generic_views import SearchView from haystack import indexes class QScriptIndex(indexes.SearchIndex, indexes.Indexable): v = indexes.CharField(document=True) def get_model(self): return QScript class QScriptSearchForm(SearchForm): text_fuzzy = forms.CharField(required=False) def search(self): sqs = super(QScriptSearchForm, self).search() if not self.is_valid(): return self.no_query_found() text_fuzzy = self.cleaned_data.get('text_fuzzy') if text_fuzzy: sqs = sqs.filter(text__fuzzy=text_fuzzy) return sqs class QScriptSearchView(SearchView): form_class = QScriptSearchForm
Update: if PostgreSQL has a Levenshtein distance function, you can also use it as a Haystack backend or as a standalone search engine. If you choose the second method, you will need to execute a custom query expression , which is relatively simple if you use the latest version of Django.
source share