Description
Hi
I've googling and I'm having a lot of problem getting how to query properly.
Having:
*********** models.py *******************
class Account(models.Model):
name = models.CharField(max_length=128, db_index=True)
description = models.TextField(blank=True, null=True)
email = models.EmailField(max_length=254, db_index=True)
....
********* analyzers.py *********************
def ngram_filter(min=2, max=15):
return token_filter(
f"ngram_{min}_{max}_filter",
type="ngram",
min_gram=min,
max_gram=max
)
def edge_gram_filter(min=2, max=15):
return token_filter(
f"edgegram_{min}_{max}_filter",
type="edge_ngram",
min_gram=min,
max_gram=max
)
def stop_words_filter():
return [
english_stop_words_filter,
portuguese_stop_words_filter,
]
filters = stop_words_filter()
filters.append(ngram_filter(3, 3))
filters.append(edge_gram_filter(2, 15))
full_searchable_analyzer = analyzer(
"full_searchable_analyzer",
tokenizer="keyword",
filter=filters
)
full_searchable_analyzer = analyzer(
"full_searchable_analyzer",
tokenizer="keyword",
filter=filters
)
string_sort_analyzer = analyzer(
'string_sort',
type="keyword",
filter=[
"lowercase",
]
)
************** documents.py ********************
@registry.register_document
class AccountDocument(Document):
name = fields.TextField(
attr="name",
fields={
'raw': fields.TextField(
analyzer=full_searchable_analyzer,
search_analyzer=string_sort_analyzer
),
'suggest': fields.CompletionField(),
}
)
description = fields.TextField(
fields={
'raw': fields.TextField(
analyzer=string_sort_analyzer,
search_analyzer=string_sort_analyzer
),
'suggest': fields.CompletionField(),
}
)
class Index:
name = 'accounts'
settings = {'number_of_shards': 1,
'number_of_replicas': 0}
class Django:
model = Account
fields = [
'email',
]
objects data:
1-> {name: 'teste', description: 'testify a common taste', email: '[email protected]'}
2-> {name: 'testJonhy', description: ' asdasdkasçkdkldas', email: '[email protected]'}
3-> {name: 'Mariah', description: 'desctestsherealso', email: '[email protected]'}
s.query(MultiMatch(query='test', fields=fields, fuzziness=10)).execute()
returns record 1
s.query("match_phrase", query='test').execute()
returns nothing
q = s.filter("match_phrase", query='test').execute()
returns nothing also
How can I make query's properly?
The goal is to query and return all this documents.
Also I pretend to highlight and add Did You Mean feature.
And I've already acomplish sugestions with:
s.suggest('name', 'test', completion={'field': 'name.suggest'}).execute()
Can someone help me or point me some documentation where I can figure this out
Thanks