Skip to content

Push dev to main #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Feb 22, 2022
Merged
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ dmypy.json
# mongo db data
/mongo_data

/esdata

# Virtualenv
venv

Expand Down
3 changes: 2 additions & 1 deletion docker-compose.elasticsearch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ services:
volumes:
- ./stac_fastapi:/app/stac_fastapi
- ./scripts:/app/scripts
- ./esdata:/usr/share/elasticsearch/data
depends_on:
- elasticsearch
command:
Expand All @@ -44,4 +45,4 @@ services:

networks:
default:
name: stac-fastapi-network
name: stac-fastapi-es-network
2 changes: 1 addition & 1 deletion stac_fastapi/elasticsearch/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@


setup(
name="stac-fastapi.elasticsearch",
name="stac-fastapi.nosql.elasticsearch",
description="An implementation of STAC API based on the FastAPI framework.",
long_description=desc,
long_description_content_type="text/markdown",
Expand Down
26 changes: 18 additions & 8 deletions stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,17 @@ def item_collection(
links = []
base_url = str(kwargs["request"].base_url)

collection_children = self.client.search(
index="stac_items",
doc_type="_doc",
query={"match_phrase": {"collection": collection_id}},
search = Search(using=self.client, index="stac_items")

collection_filter = Q(
"bool", should=[Q("match_phrase", **{"collection": collection_id})]
)
search = search.query(collection_filter)

count = search.count()
# search = search.sort({"id.keyword" : {"order" : "asc"}})
search = search.query()[0:limit]
collection_children = search.execute().to_dict()

serialized_children = [
self.item_serializer.db_to_stac(item["_source"], base_url=base_url)
Expand All @@ -113,8 +119,11 @@ def item_collection(

context_obj = None
if self.extension_is_enabled("ContextExtension"):
count = len(serialized_children)
context_obj = {"returned": count, "limit": limit, "matched": count}
context_obj = {
"returned": count if count < limit else limit,
"limit": limit,
"matched": count,
}

return ItemCollection(
type="FeatureCollection",
Expand Down Expand Up @@ -307,7 +316,9 @@ def post_search(
field = sort.field + ".keyword"
search = search.sort({field: {"order": sort.direction}})

count = search.count()
# search = search.sort({"id.keyword" : {"order" : "asc"}})
search = search.query()[0 : search_request.limit]
response = search.execute().to_dict()

if len(response["hits"]["hits"]) > 0:
Expand Down Expand Up @@ -347,9 +358,8 @@ def post_search(
limit = 10
context_obj = None
if self.extension_is_enabled("ContextExtension"):
count = len(response_features)
context_obj = {
"returned": count if count <= 10 else limit,
"returned": count if count < limit else limit,
"limit": limit,
"matched": count,
}
Expand Down
2 changes: 1 addition & 1 deletion stac_fastapi/mongo/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@


setup(
name="stac-fastapi.mongo",
name="stac-fastapi.nosql.mongo",
description="An implementation of STAC API based on the FastAPI framework.",
long_description=desc,
long_description_content_type="text/markdown",
Expand Down
21 changes: 15 additions & 6 deletions stac_fastapi/mongo/stac_fastapi/mongo/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,19 @@ def item_collection(
base_url = str(kwargs["request"].base_url)

with self.client.start_session() as session:
collection_children = self.item_table.find(
{"collection": collection_id}, session=session
).sort(
[("properties.datetime", pymongo.ASCENDING), ("id", pymongo.ASCENDING)]
collection_children = (
self.item_table.find({"collection": collection_id}, session=session)
.limit(limit)
.sort(
[
("properties.datetime", pymongo.ASCENDING),
("id", pymongo.ASCENDING),
]
)
)

matched = self.item_table.count_documents({"collection": collection_id})

for item in collection_children:
response_features.append(
self.item_serializer.db_to_stac(item, base_url=base_url)
Expand All @@ -120,7 +127,7 @@ def item_collection(
context_obj = {
"returned": count if count <= 10 else limit,
"limit": limit,
"matched": len(response_features) or None,
"matched": matched or None,
}

return ItemCollection(
Expand Down Expand Up @@ -296,6 +303,8 @@ def post_search(
.sort(sort_list)
)

matched = self.item_table.count_documents(queries)

results = []
links = []

Expand Down Expand Up @@ -329,7 +338,7 @@ def post_search(
context_obj = {
"returned": count if count <= 10 else search_request.limit,
"limit": search_request.limit,
"matched": len(results) or None,
"matched": matched or None,
}

return ItemCollection(
Expand Down