Skip to content

Commit 6bc2d7a

Browse files
authored
Merge pull request #18 from jonhealy1/dev
Push dev to main
2 parents defac44 + b74aa2b commit 6bc2d7a

File tree

6 files changed

+39
-17
lines changed

6 files changed

+39
-17
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ dmypy.json
131131
# mongo db data
132132
/mongo_data
133133

134+
/esdata
135+
134136
# Virtualenv
135137
venv
136138

docker-compose.elasticsearch.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ services:
2424
volumes:
2525
- ./stac_fastapi:/app/stac_fastapi
2626
- ./scripts:/app/scripts
27+
- ./esdata:/usr/share/elasticsearch/data
2728
depends_on:
2829
- elasticsearch
2930
command:
@@ -44,4 +45,4 @@ services:
4445

4546
networks:
4647
default:
47-
name: stac-fastapi-network
48+
name: stac-fastapi-es-network

stac_fastapi/elasticsearch/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434

3535
setup(
36-
name="stac-fastapi.elasticsearch",
36+
name="stac-fastapi.nosql.elasticsearch",
3737
description="An implementation of STAC API based on the FastAPI framework.",
3838
long_description=desc,
3939
long_description_content_type="text/markdown",

stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/core.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,17 @@ def item_collection(
100100
links = []
101101
base_url = str(kwargs["request"].base_url)
102102

103-
collection_children = self.client.search(
104-
index="stac_items",
105-
doc_type="_doc",
106-
query={"match_phrase": {"collection": collection_id}},
103+
search = Search(using=self.client, index="stac_items")
104+
105+
collection_filter = Q(
106+
"bool", should=[Q("match_phrase", **{"collection": collection_id})]
107107
)
108+
search = search.query(collection_filter)
109+
110+
count = search.count()
111+
# search = search.sort({"id.keyword" : {"order" : "asc"}})
112+
search = search.query()[0:limit]
113+
collection_children = search.execute().to_dict()
108114

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

114120
context_obj = None
115121
if self.extension_is_enabled("ContextExtension"):
116-
count = len(serialized_children)
117-
context_obj = {"returned": count, "limit": limit, "matched": count}
122+
context_obj = {
123+
"returned": count if count < limit else limit,
124+
"limit": limit,
125+
"matched": count,
126+
}
118127

119128
return ItemCollection(
120129
type="FeatureCollection",
@@ -307,7 +316,9 @@ def post_search(
307316
field = sort.field + ".keyword"
308317
search = search.sort({field: {"order": sort.direction}})
309318

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

313324
if len(response["hits"]["hits"]) > 0:
@@ -347,9 +358,8 @@ def post_search(
347358
limit = 10
348359
context_obj = None
349360
if self.extension_is_enabled("ContextExtension"):
350-
count = len(response_features)
351361
context_obj = {
352-
"returned": count if count <= 10 else limit,
362+
"returned": count if count < limit else limit,
353363
"limit": limit,
354364
"matched": count,
355365
}

stac_fastapi/mongo/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333

3434
setup(
35-
name="stac-fastapi.mongo",
35+
name="stac-fastapi.nosql.mongo",
3636
description="An implementation of STAC API based on the FastAPI framework.",
3737
long_description=desc,
3838
long_description_content_type="text/markdown",

stac_fastapi/mongo/stac_fastapi/mongo/core.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,19 @@ def item_collection(
103103
base_url = str(kwargs["request"].base_url)
104104

105105
with self.client.start_session() as session:
106-
collection_children = self.item_table.find(
107-
{"collection": collection_id}, session=session
108-
).sort(
109-
[("properties.datetime", pymongo.ASCENDING), ("id", pymongo.ASCENDING)]
106+
collection_children = (
107+
self.item_table.find({"collection": collection_id}, session=session)
108+
.limit(limit)
109+
.sort(
110+
[
111+
("properties.datetime", pymongo.ASCENDING),
112+
("id", pymongo.ASCENDING),
113+
]
114+
)
110115
)
111116

117+
matched = self.item_table.count_documents({"collection": collection_id})
118+
112119
for item in collection_children:
113120
response_features.append(
114121
self.item_serializer.db_to_stac(item, base_url=base_url)
@@ -120,7 +127,7 @@ def item_collection(
120127
context_obj = {
121128
"returned": count if count <= 10 else limit,
122129
"limit": limit,
123-
"matched": len(response_features) or None,
130+
"matched": matched or None,
124131
}
125132

126133
return ItemCollection(
@@ -296,6 +303,8 @@ def post_search(
296303
.sort(sort_list)
297304
)
298305

306+
matched = self.item_table.count_documents(queries)
307+
299308
results = []
300309
links = []
301310

@@ -329,7 +338,7 @@ def post_search(
329338
context_obj = {
330339
"returned": count if count <= 10 else search_request.limit,
331340
"limit": search_request.limit,
332-
"matched": len(results) or None,
341+
"matched": matched or None,
333342
}
334343

335344
return ItemCollection(

0 commit comments

Comments
 (0)