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 fce4bd0
Show file tree
Hide file tree
Showing 6 changed files with 2,208 additions and 14 deletions.
21 changes: 15 additions & 6 deletions pystac_client/collection_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,19 +336,28 @@ 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:
return 0

# if collection search and free-text are fully supported, try reading a value
# from the search result context
if (
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"]

if not found:
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 fce4bd0

Please sign in to comment.