Skip to content

Commit

Permalink
Merge branch 'main' into feat-#15380
Browse files Browse the repository at this point in the history
  • Loading branch information
Sachin-chaurasiya authored Dec 18, 2024
2 parents 5725f9f + a49aab7 commit 84f1449
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
24 changes: 19 additions & 5 deletions ingestion/src/metadata/ingestion/ometa/mixins/user_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
To be used by OpenMetadata class
"""
import json
from functools import lru_cache
from typing import Optional, Type

Expand Down Expand Up @@ -46,16 +47,29 @@ def email_search_query_es(entity: Type[T]) -> str:
)

@staticmethod
def name_search_query_es(entity: Type[T]) -> str:
def name_search_query_es(entity: Type[T], name: str, from_: int, size: int) -> str:
"""
Allow for more flexible lookup following what the UI is doing when searching users.
We don't want to stick to `q=name:{name}` since in case a user is named `random.user`
but looked as `Random User`, we want to find this match.
Search should only look in name and displayName fields and should not return bots.
"""
query_filter = {
"query": {
"query_string": {
"query": f"{name} AND isBot:false",
"fields": ["name", "displayName"],
"default_operator": "AND",
"fuzziness": "AUTO",
}
}
}

return (
"/search/query?q={name} AND isBot:false&from={from_}&size={size}&index="
+ ES_INDEX_MAP[entity.__name__]
f"""/search/query?query_filter={json.dumps(query_filter)}"""
f"&from={from_}&size={size}&index=" + ES_INDEX_MAP[entity.__name__]
)

def _search_by_email(
Expand Down Expand Up @@ -103,8 +117,8 @@ def _search_by_name(
fields: Optional field list to pass to ES request
"""
if name:
query_string = self.name_search_query_es(entity=entity).format(
name=name, from_=from_count, size=size
query_string = self.name_search_query_es(
entity=entity, name=name, from_=from_count, size=size
)
return self.get_entity_from_es(
entity=entity, query_string=query_string, fields=fields
Expand Down
9 changes: 8 additions & 1 deletion ingestion/tests/integration/ometa/test_ometa_user_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ def setUpClass(cls) -> None:

cls.user_1: User = cls.metadata.create_or_update(
data=CreateUserRequest(
name="random.user.es", email="random.user.es@getcollate.io"
name="random.user.es",
email="random.user.es@getcollate.io",
description="test",
),
)

Expand Down Expand Up @@ -198,3 +200,8 @@ def test_es_search_from_name(self):
self.assertIsNone(
self.metadata.get_reference_by_name(name="Organization", is_owner=True)
)

# description should not affect in search
self.assertIsNone(
self.metadata.get_reference_by_name(name="test", is_owner=True)
)

0 comments on commit 84f1449

Please sign in to comment.