Skip to content

Commit

Permalink
allow using query with sub containers endpoint and add swagger docume…
Browse files Browse the repository at this point in the history
…nts for the new url
  • Loading branch information
khaledk2 committed Nov 26, 2024
1 parent 87ff623 commit bf4b7dd
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 11 deletions.
12 changes: 3 additions & 9 deletions omero_search_engine/api/v1/resources/resource_analyser.py
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,6 @@ def process_container_query(
{"terms": {"field": "key_values.value.keyvalue","size": 10000}}}}}}}"""
)


"""
Get all the keys bucket"""
container_project_keys_template = {
Expand Down Expand Up @@ -1005,13 +1004,10 @@ def process_container_query(


def get_containers_no_images(
contianer, container_name, sub_container=None, query_details=None
contianer, container_name, query_details=None
):
containers_subcontainers = {"project": "dataset", "screen": "plate"}
if not sub_container:
if not containers_subcontainers.get(contianer.lower()):
return "No sub container is found, please check the container type"
sub_container = containers_subcontainers[contianer]
sub_container = containers_subcontainers[contianer]
res_index = resource_elasticsearchindex.get("image")
aggs_part = container_returned_sub_container_template.substitute(
container_attribute_name="%s_name.keyvalue" % contianer,
Expand All @@ -1024,7 +1020,7 @@ def get_containers_no_images(
and_filters = query_details.get("and_filters")
or_filters = query_details.get("or_filters")
case_sensitive = query_details.get("case_sensitive")
main_attributes = query.get("main_attributes")
main_attributes = query_details.get("main_attributes")
from omero_search_engine.api.v1.resources.utils import (
elasticsearch_query_builder,
)
Expand All @@ -1038,8 +1034,6 @@ def get_containers_no_images(
query["aggs"] = json.loads(aggs_part)
res = search_index_for_value(res_index, query)
buckets = res["aggregations"]["values"]["uniquesTerms"]["buckets"]
print(len(buckets))
print(buckets[0])
returned_results = []
for bucket in buckets:
returned_results.append(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
A searchengine endpoint to Return the available containers and the number of images in each.
---
tags:
- Containers and the number of images in each.

responses:
200:
description: A JSON contains the search results
examples:
results: []
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
A searchengine endpoint to return the available sub-container in a container (e.g. dataset in project)
A query can be provided to return only the search results
---
tags:
- Available sub-containers inside a container
parameters:
- name: container
in: query
type: string
enum: ['project', 'screen']
required: true
- name: container_name
description: The container name
in: query
type: string
required: true
- name: data
in: body
required: false

responses:
200:
description: A JSON contains the search results
examples:
results: []
31 changes: 29 additions & 2 deletions omero_search_engine/api/v1/resources/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,9 @@ def container_keys_search(resource_table):

@resources.route("/container_images/", methods=["GET"])
def container_images():
"""
file: swagger_docs/container_images.yml
"""
from omero_search_engine.api.v1.resources.resource_analyser import (
return_containes_images,
)
Expand All @@ -476,12 +479,36 @@ def container_images():


# to do: add query to return the results withiz the sub-container
@resources.route("/sub_container_images/", methods=["GET"])
@resources.route("/sub_container_images/", methods=["POST","GET"])
def sub_container_images():
"""
file: swagger_docs/sub_container_images.yml
"""
from omero_search_engine.api.v1.resources.resource_analyser import (
get_containers_no_images,
)

container = request.args.get("container")
container_name = request.args.get("container_name")
return get_containers_no_images(container, container_name)
if not container_name or not container:
return jsonify(
build_error_message(
"{error}".format(error="container and container name are required.")
)
)
data = request.data
query={}
if data:
try:
data = json.loads(data)
except Exception:
return jsonify(
build_error_message(
"{error}".format(error="No proper query data is provided.")
)
)

if "query_details" in data:
query = data["query_details "]

return get_containers_no_images(container, container_name, query)

0 comments on commit bf4b7dd

Please sign in to comment.