@@ -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 }
0 commit comments