Skip to content

Commit 1457fbb

Browse files
committed
improve matched logic
1 parent ef2ba04 commit 1457fbb

File tree

6 files changed

+2207
-15
lines changed

6 files changed

+2207
-15
lines changed

pystac_client/collection_search.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -336,19 +336,27 @@ def matched(self) -> Optional[int]:
336336
int: Total count of matched collections. If counts are not supported `None`
337337
is returned.
338338
"""
339-
params = {**self.get_parameters(), "limit": 1}
340-
resp = self._stac_io.read_json(self.url, method=self.method, parameters=params)
341339
found = None
340+
iter = self.pages_as_dicts()
341+
page = next(iter, None)
342+
343+
if not page:
344+
pass
345+
342346
# if collection search and free-text are fully supported, try reading a value
343347
# from the search result context
344-
if (
348+
elif (
345349
self._collection_search_extension_enabled
346350
and self._collection_search_free_text_enabled
347351
):
348-
if "context" in resp:
349-
found = resp["context"].get("matched", None)
350-
elif "numberMatched" in resp:
351-
found = resp["numberMatched"]
352+
if "context" in page:
353+
found = page["context"].get("matched", None)
354+
elif "numberMatched" in page:
355+
found = page["numberMatched"]
356+
else:
357+
count = len(page["collections"])
358+
for page in iter:
359+
count += len(page["collections"])
352360

353361
# if context is missing or if collection search and free-text are not supported,
354362
# just count the records

0 commit comments

Comments
 (0)