Last active
January 8, 2019 01:04
-
-
Save kaedroho/96c605acaa9ef992b7d297a69f0be46d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from wagtail.wagtailsearch.backends.elasticsearch import ElasticsearchSearchBackend, ElasticsearchSearchQuery | |
class ElasticSearchQueryWithFuzziness(ElasticsearchSearchQuery): | |
def get_inner_query(self): | |
if self.query_string is not None: | |
fields = self.fields or ['_all', '_partials'] | |
if len(fields) == 1: | |
query = { | |
'match': { | |
fields[0]: { | |
'query': self.query_string, | |
'operator': self.operator, | |
'fuzziness': 'AUTO', | |
} | |
} | |
} | |
else: | |
query = { | |
'multi_match': { | |
'query': self.query_string, | |
'fields': fields, | |
'operator': self.operator, | |
'fuzziness': 'AUTO', | |
} | |
} | |
else: | |
query = { | |
'match_all': {} | |
} | |
return query | |
class CustomElasticSearch(ElasticsearchSearchBackend): | |
search_query_class = ElasticSearchQueryWithFuzziness | |
SearchBackend = CustomElasticSearch |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's a version that works with Wagtail 2.4 & Elasticsearch6. I have only tested this briefly.
or perhaps alternatively: