Elastic: include exact searches on email address
This commit is contained in:
parent
6e40b9a44a
commit
4fdcd2a343
@ -53,6 +53,7 @@ class User(es.DocType):
|
||||
fielddata=True,
|
||||
analyzer=autocomplete,
|
||||
)
|
||||
email_exact = es.Keyword()
|
||||
|
||||
class Meta:
|
||||
index = 'users'
|
||||
@ -131,6 +132,8 @@ def create_doc_from_user_data(user_to_index: dict) -> User:
|
||||
doc.roles = list(map(str, user_to_index['roles']))
|
||||
doc.groups = list(map(str, user_to_index['groups']))
|
||||
doc.email = user_to_index['email']
|
||||
doc.email_exact = user_to_index['email']
|
||||
|
||||
return doc
|
||||
|
||||
|
||||
|
@ -123,6 +123,9 @@ def _common_user_search(query: str) -> (typing.List[Query], typing.List[Query]):
|
||||
Q('match', email=query),
|
||||
]
|
||||
|
||||
if '@' in query:
|
||||
should.append(Q('term', email_exact=query))
|
||||
|
||||
return [], should
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user