Skip to content

Commit

Permalink
Fix issue of return container by container name
Browse files Browse the repository at this point in the history
  • Loading branch information
khaledk2 committed Nov 28, 2024
1 parent 09e2b78 commit 2332e03
Showing 1 changed file with 60 additions and 26 deletions.
86 changes: 60 additions & 26 deletions omero_search_engine/api/v1/resources/query_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,19 @@

res_and_main_attributes = None
res_or_main_attributes = None
data_sources = []


def reset_global_values():
global res_and_main_attributes, res_or_main_attributes
global res_and_main_attributes, res_or_main_attributes, data_sources
res_and_main_attributes = None
res_or_main_attributes = None
data_sources = []


def check_get_names(idr_, resource, attribute, data_source, return_exact=False):
# check the idr name and return the resource and possible values
global data_sources
if idr_:
idr_ = idr_.strip()
pr_names = get_resource_names(resource)
Expand All @@ -61,7 +64,7 @@ def check_get_names(idr_, resource, attribute, data_source, return_exact=False):
):
continue
act_name = [
name["id"]
{"id": name["id"], "data_source": data_source_}
for name in pr_names_
if name[attribute] and idr_.lower() in name[attribute].lower()
]
Expand All @@ -77,12 +80,18 @@ def check_get_names(idr_, resource, attribute, data_source, return_exact=False):
):
continue
act_name = [
name["id"]
{"id": name["id"], "data_source": data_source_}
for name in pr_names_
if name[attribute] and idr_.lower() == name[attribute].lower()
if name[attribute] and idr_.lower() in name[attribute].lower()
]
all_act_names = all_act_names + act_name
return all_act_names
returned_act_names = []
for act in all_act_names:
returned_act_names.append(act["id"])
if act["data_source"] not in data_sources:
data_sources.append(act["data_source"])

return returned_act_names


class QueryItem(object):
Expand Down Expand Up @@ -433,7 +442,7 @@ def run_query(self, query_, resource):
# res = search_query(query, resource, bookmark,
# self.raw_elasticsearch_query,
# main_attributes,return_containers=self.return_containers)
global res_and_main_attributes, res_or_main_attributes
global res_and_main_attributes, res_or_main_attributes, data_sources
if res_and_main_attributes:
if main_attributes.get("and_main_attributes"):
main_attributes["and_main_attributes"] = (
Expand All @@ -442,27 +451,52 @@ def run_query(self, query_, resource):
else:
main_attributes["and_main_attributes"] = res_and_main_attributes
if resource == "image" and self.return_containers:
res = search_query(
query,
resource,
bookmark,
pagination_dict,
self.raw_elasticsearch_query,
main_attributes,
return_containers=self.return_containers,
data_source=self.data_source,
)
else:
res = search_query(
query,
resource,
bookmark,
pagination_dict,
self.raw_elasticsearch_query,
main_attributes,
data_source=self.data_source,
)
if len(data_sources) > 0:
res = search_query(
query,
resource,
bookmark,
pagination_dict,
self.raw_elasticsearch_query,
main_attributes,
return_containers=self.return_containers,
# data_source=self.data_source,
data_source=",".join(data_sources),
)
else:
res = search_query(
query,
resource,
bookmark,
pagination_dict,
self.raw_elasticsearch_query,
main_attributes,
return_containers=self.return_containers,
data_source=self.data_source,
)

else:
if len(data_sources) > 0:
res = search_query(
query,
resource,
bookmark,
pagination_dict,
self.raw_elasticsearch_query,
main_attributes,
# data_source=self.data_source,
data_source=",".join(data_sources),
)
else:
res = search_query(
query,
resource,
bookmark,
pagination_dict,
self.raw_elasticsearch_query,
main_attributes,
data_source=self.data_source,
)
if resource != "image":
return res
elif self.return_columns:
Expand Down

0 comments on commit 2332e03

Please sign in to comment.