|
22 | 22 | EmptyResults,
|
23 | 23 | log_query,
|
24 | 24 | )
|
25 |
| -from haystack.constants import DJANGO_CT, DJANGO_ID, ID |
| 25 | +from haystack.constants import ( |
| 26 | + DJANGO_CT, |
| 27 | + DJANGO_ID, |
| 28 | + FUZZY_WHOOSH_MAX_EDITS, |
| 29 | + FUZZY_WHOOSH_MIN_PREFIX, |
| 30 | + ID, |
| 31 | +) |
26 | 32 | from haystack.exceptions import MissingDependency, SearchBackendError, SkipDocument
|
27 | 33 | from haystack.inputs import Clean, Exact, PythonData, Raw
|
28 | 34 | from haystack.models import SearchResult
|
|
59 | 65 | from whoosh.filedb.filestore import FileStorage, RamStorage
|
60 | 66 | from whoosh.highlight import highlight as whoosh_highlight
|
61 | 67 | from whoosh.highlight import ContextFragmenter, HtmlFormatter
|
62 |
| -from whoosh.qparser import QueryParser |
| 68 | +from whoosh.qparser import QueryParser, FuzzyTermPlugin |
63 | 69 | from whoosh.searching import ResultsPage
|
64 | 70 | from whoosh.writing import AsyncWriter
|
65 | 71 |
|
@@ -162,6 +168,7 @@ def setup(self):
|
162 | 168 | connections[self.connection_alias].get_unified_index().all_searchfields()
|
163 | 169 | )
|
164 | 170 | self.parser = QueryParser(self.content_field_name, schema=self.schema)
|
| 171 | + self.parser.add_plugins([FuzzyTermPlugin]) |
165 | 172 |
|
166 | 173 | if new_index is True:
|
167 | 174 | self.index = self.storage.create_index(self.schema)
|
@@ -959,7 +966,7 @@ def build_query_fragment(self, field, filter_type, value):
|
959 | 966 | "gte": "[%s to]",
|
960 | 967 | "lt": "{to %s}",
|
961 | 968 | "lte": "[to %s]",
|
962 |
| - "fuzzy": "%s~", |
| 969 | + 'fuzzy': "%s~{}/{}".format(FUZZY_WHOOSH_MAX_EDITS, FUZZY_WHOOSH_MIN_PREFIX), |
963 | 970 | }
|
964 | 971 |
|
965 | 972 | if value.post_process is False:
|
|
0 commit comments