user search: boost exact matches on username
This commit is contained in:
@@ -37,6 +37,7 @@ class User(es.DocType):
|
|||||||
objectID = es.Keyword()
|
objectID = es.Keyword()
|
||||||
|
|
||||||
username = es.String(fielddata=True, analyzer=autocomplete)
|
username = es.String(fielddata=True, analyzer=autocomplete)
|
||||||
|
username_exact = es.Keyword()
|
||||||
full_name = es.String(fielddata=True, analyzer=autocomplete)
|
full_name = es.String(fielddata=True, analyzer=autocomplete)
|
||||||
|
|
||||||
roles = es.Keyword(multi=True)
|
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 = User(_id=doc_id)
|
||||||
doc.objectID = str(user_to_index['objectID'])
|
doc.objectID = str(user_to_index['objectID'])
|
||||||
doc.username = user_to_index['username']
|
doc.username = user_to_index['username']
|
||||||
|
doc.username_exact = user_to_index['username']
|
||||||
doc.full_name = user_to_index['full_name']
|
doc.full_name = user_to_index['full_name']
|
||||||
doc.roles = list(map(str, user_to_index['roles']))
|
doc.roles = list(map(str, user_to_index['roles']))
|
||||||
doc.groups = list(map(str, user_to_index['groups']))
|
doc.groups = list(map(str, user_to_index['groups']))
|
||||||
|
@@ -121,6 +121,7 @@ def _common_user_search(query: str) -> (typing.List[Query], typing.List[Query]):
|
|||||||
Q('match', username=query),
|
Q('match', username=query),
|
||||||
Q('match', full_name=query),
|
Q('match', full_name=query),
|
||||||
Q('match', email=query),
|
Q('match', email=query),
|
||||||
|
{'term': {'username_exact': {'value': query, 'boost': 50}}},
|
||||||
]
|
]
|
||||||
|
|
||||||
if '@' in query:
|
if '@' in query:
|
||||||
|
Reference in New Issue
Block a user