Skip to content

Commit

Permalink
add search by one data source or more for searchannotaion endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
khaledk2 committed Aug 24, 2024
1 parent ec58235 commit 80bf4c2
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
1 change: 0 additions & 1 deletion omero_search_engine/api/v1/resources/query_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,6 @@ def add_local_schemas_to(resolver, schema_folder, base_uri, schema_ext=".json"):


def query_validator(query):
print("TRoz", query)
main_dir = os.path.abspath(os.path.dirname(__file__))
query_schema_file = os.path.join(main_dir, "schemas", "query_data.json")
base_uri = "file:" + abspath("") + "/"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ parameters:
in: query
type: boolean
required: false
- name: data_source
in: query
type: string
required: false
# required:
# - and_filter
# - or_filter
Expand Down
5 changes: 4 additions & 1 deletion omero_search_engine/api/v1/resources/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def search_resource_page(resource_table):
raw_elasticsearch_query = data.get("raw_elasticsearch_query")
pagination_dict = data.get("pagination")
return_containers = data.get("return_containers")
data_source = request.args.get("data_source")
if return_containers:
return_containers = json.loads(return_containers.lower())

Expand All @@ -100,6 +101,7 @@ def search_resource_page(resource_table):
bookmark=bookmark,
pagination_dict=pagination_dict,
return_containers=return_containers,
data_source=data_source
)
return jsonify(resource_list)
else:
Expand Down Expand Up @@ -169,11 +171,12 @@ def search_resource(resource_table):
validation_results = query_validator(query)
if validation_results == "OK":
return_containers = request.args.get("return_containers")
data_source = request.args.get("data_source")
if return_containers:
return_containers = json.loads(return_containers.lower())

resource_list = search_resource_annotation(
resource_table, query, return_containers=return_containers
resource_table, query, return_containers=return_containers, data_source=data_source
)
return jsonify(resource_list)
else:
Expand Down
28 changes: 16 additions & 12 deletions omero_search_engine/api/v1/resources/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1108,19 +1108,23 @@ def search_resource_annotation(
"{query} is not a valid query".format(query=query)
)
if data_source and data_source.lower() != "all":
clause = {}
clause["name"] = "data_source"
clause["value"] = data_source
clause["operator"] = "equals"
if main_attributes and len(main_attributes) > 0:
if main_attributes.get("and_main_attributes"):
main_attributes.get("and_main_attributes").append(clause)
data_sources=get_data_sources()
data_source=data_source.split(',')
for data_s in data_source:
if data_s and data_s.strip().lower() not in data_sources:
return "'%s' is not a data source"%data_s
clause = {}
clause["name"] = "data_source"
clause["value"] = data_s
clause["operator"] = "equals"
if main_attributes and len(main_attributes) > 0:
if main_attributes.get("or_main_attributes"):
main_attributes.get("or_main_attributes").append(clause)
else:
main_attributes["or_main_attributes"] = [clause]
else:
main_attributes["and_main_attributes"] = [clause]
else:
main_attributes = {}
main_attributes["and_main_attributes"] = [clause]

main_attributes = {}
main_attributes["or_main_attributes"] = [clause]
and_filters = query_details.get("and_filters")
or_filters = query_details.get("or_filters")
case_sensitive = query_details.get("case_sensitive")
Expand Down

0 comments on commit 80bf4c2

Please sign in to comment.