@@ -75,19 +75,14 @@ async def get_all_collections(self, base_url: str) -> List[Collection]:
7575 for c in collections ["hits" ]["hits" ]
7676 ]
7777
78- async def search_count (self , search : Search ) -> Optional [int ]:
79- """Database logic to count search results."""
80- return (
81- await self .client .count (index = ITEMS_INDEX , body = search .to_dict (count = True ))
82- ).get ("count" )
83-
8478 async def get_collection_items (
8579 self , collection_id : str , limit : int , base_url : str
8680 ) -> Tuple [List [Item ], Optional [int ]]:
8781 """Database logic to retrieve an ItemCollection and a count of items contained."""
8882 search = self .apply_collections_filter (Search (), [collection_id ])
89- items = await self .execute_search (search = search , limit = limit , base_url = base_url )
90- maybe_count = await self .search_count (search )
83+ items , maybe_count = await self .execute_search (
84+ search = search , limit = limit , base_url = base_url
85+ )
9186
9287 return items , maybe_count
9388
@@ -199,20 +194,28 @@ def apply_sort(search: Search, field, direction):
199194 """Database logic to sort search instance."""
200195 return search .sort ({field : {"order" : direction }})
201196
202- async def execute_search (self , search , limit : int , base_url : str ) -> List [Item ]:
197+ async def execute_search (
198+ self , search , limit : int , base_url : str
199+ ) -> Tuple [List [Item ], Optional [int ]]:
203200 """Database logic to execute search with limit."""
204201 search = search [0 :limit ]
205202 body = search .to_dict ()
206203
204+ maybe_count = (
205+ await self .client .count (index = ITEMS_INDEX , body = search .to_dict (count = True ))
206+ ).get ("count" )
207+
207208 es_response = await self .client .search (
208209 index = ITEMS_INDEX , query = body .get ("query" ), sort = body .get ("sort" )
209210 )
210211
211- return [
212+ items = [
212213 self .item_serializer .db_to_stac (hit ["_source" ], base_url = base_url )
213214 for hit in es_response ["hits" ]["hits" ]
214215 ]
215216
217+ return items , maybe_count
218+
216219 """ TRANSACTION LOGIC """
217220
218221 async def check_collection_exists (self , collection_id : str ):
0 commit comments