Djagno и ElasticSearch как разрешить поиск с опечатками
Я довольно новичок в эластичном поиске и хочу включить поиск с опечатками (максимум 2 буквы)
пример
input: gpple
result: google
/////////////
input: convarsetyon (3 letters typos, meant to be : conversation )
result: none
моим бэкендом является Django, а способ взаимодействия с elastic search - через elasticsearch-dsl. Я попытался реализовать добавление атрибута fuzziness в запрос wildcard, но это привело к ошибке
views.py:
class SearchRecipes(ListAPIView):
serializer_class = RecipeSearchSerializer
def get_queryset(self, *args, **kwargs):
word = self.kwargs['word']
recipeQueryset = RecipeDocument.search().query('wildcard',title=f'*{word}*').sort("-score")
return recipeQueryset
documents.py
autocomplete_analyzer = analyzer('autocomplete_analyzer',
tokenizer=tokenizer('trigram', 'edge_ngram', min_gram=1, max_gram=20),
filter=['lowercase']
)
@registry.register_document
class RecipeDocument(Document):
title = fields.TextField(required=True, analyzer=autocomplete_analyzer)
class Index:
name = 'recipes'
settings = {
'number_of_shards': 1,
'number_of_replicas': 0,
'max_ngram_diff': 20
}
class Django:
model = Recipe
fields = [
'score',
]
Кто-нибудь знает, как это сделать? Заранее спасибо