From f7c473c31d52ef7fd3c706cdadd0d6195b1b97c0 Mon Sep 17 00:00:00 2001 From: shayanaijaz Date: Wed, 18 Oct 2023 17:21:13 -0500 Subject: [PATCH] fix project file search bug, added search on project id --- server/portal/apps/projects/views.py | 4 ++-- server/portal/libs/agave/operations.py | 2 +- server/portal/libs/elasticsearch/docs/base.py | 2 +- server/portal/libs/elasticsearch/utils.py | 2 -- 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/server/portal/apps/projects/views.py b/server/portal/apps/projects/views.py index 26de7150d..ca03a8479 100644 --- a/server/portal/apps/projects/views.py +++ b/server/portal/apps/projects/views.py @@ -76,11 +76,11 @@ def get(self, request): search = IndexedProject.search() ngram_query = Q("query_string", query=query_string, - fields=["title"], + fields=["title", "id"], minimum_should_match='100%', default_operator='or') - wildcard_query = Q("wildcard", title=f'*{query_string}*') + wildcard_query = Q("wildcard", title=f'*{query_string}*') | Q("wildcard", id=f'*{query_string}*') search = search.query(ngram_query | wildcard_query) search = search.extra(from_=int(offset), size=int(limit)) diff --git a/server/portal/libs/agave/operations.py b/server/portal/libs/agave/operations.py index 0131dcef8..83264a1a8 100644 --- a/server/portal/libs/agave/operations.py +++ b/server/portal/libs/agave/operations.py @@ -139,7 +139,7 @@ def search(client, system, path='', offset=0, limit=100, query_string='', filter if filter: search = search.filter(filter_query) - search = search.filter('prefix', **{'path._exact': path}) + search = search.filter('prefix', **{'path._exact': path.strip('/')}) search = search.filter('term', **{'system._exact': system}) search = search.extra(from_=int(offset), size=int(limit)) res = search.execute() diff --git a/server/portal/libs/elasticsearch/docs/base.py b/server/portal/libs/elasticsearch/docs/base.py index e86d605df..c52b36be7 100644 --- a/server/portal/libs/elasticsearch/docs/base.py +++ b/server/portal/libs/elasticsearch/docs/base.py @@ -17,7 +17,7 @@ class IndexedProject(Document): - id = Keyword() + id = Keyword(fields={'_exact': Keyword()}) title = Text(fields={'_exact': Keyword()}) description = Text() path = Text() diff --git a/server/portal/libs/elasticsearch/utils.py b/server/portal/libs/elasticsearch/utils.py index 64c3adc07..90666209f 100644 --- a/server/portal/libs/elasticsearch/utils.py +++ b/server/portal/libs/elasticsearch/utils.py @@ -207,8 +207,6 @@ def index_listing(files): file_dict = dict(_file) if file_dict['name'][0] == '.': continue - if not file_dict['path'].startswith('/'): - file_dict['path'] = '/' + file_dict['path'] file_dict['lastUpdated'] = current_time() file_dict['basePath'] = os.path.dirname(file_dict['path']) file_uuid = file_uuid_sha256(file_dict['system'], file_dict['path'])