user search: boost exact matches on username

This commit is contained in:
Sybren A. Stüvel 2018-01-10 15:12:39 +01:00
parent 7f892601f4
commit 36da289746
2 changed files with 3 additions and 0 deletions

View File

@ -37,6 +37,7 @@ class User(es.DocType):
objectID = es.Keyword()
username = es.String(fielddata=True, analyzer=autocomplete)
username_exact = es.Keyword()
full_name = es.String(fielddata=True, analyzer=autocomplete)
roles = es.Keyword(multi=True)
@ -118,6 +119,7 @@ def create_doc_from_user_data(user_to_index: dict) -> typing.Optional[User]:
doc = User(_id=doc_id)
doc.objectID = str(user_to_index['objectID'])
doc.username = user_to_index['username']
doc.username_exact = user_to_index['username']
doc.full_name = user_to_index['full_name']
doc.roles = list(map(str, user_to_index['roles']))
doc.groups = list(map(str, user_to_index['groups']))

View File

@ -121,6 +121,7 @@ def _common_user_search(query: str) -> (typing.List[Query], typing.List[Query]):
Q('match', username=query),
Q('match', full_name=query),
Q('match', email=query),
{'term': {'username_exact': {'value': query, 'boost': 50}}},
]
if '@' in query: