Skip to content

Commit

Permalink
improve matched logic
Browse files Browse the repository at this point in the history
  • Loading branch information
hrodmn committed Oct 10, 2024
1 parent ef2ba04 commit 1457fbb
Show file tree
Hide file tree
Showing 6 changed files with 2,207 additions and 15 deletions.
22 changes: 15 additions & 7 deletions pystac_client/collection_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,19 +336,27 @@ def matched(self) -> Optional[int]:
int: Total count of matched collections. If counts are not supported `None`
is returned.
"""
params = {**self.get_parameters(), "limit": 1}
resp = self._stac_io.read_json(self.url, method=self.method, parameters=params)
found = None
iter = self.pages_as_dicts()
page = next(iter, None)

if not page:
pass

# if collection search and free-text are fully supported, try reading a value
# from the search result context
if (
elif (
self._collection_search_extension_enabled
and self._collection_search_free_text_enabled
):
if "context" in resp:
found = resp["context"].get("matched", None)
elif "numberMatched" in resp:
found = resp["numberMatched"]
if "context" in page:
found = page["context"].get("matched", None)
elif "numberMatched" in page:
found = page["numberMatched"]
else:
count = len(page["collections"])
for page in iter:
count += len(page["collections"])

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

0 comments on commit 1457fbb

Please sign in to comment.