Skip to content

feat: catalogs scoped search - #463

Open
jonhealy1 wants to merge 2 commits into
stac-utils:mainfrom
jonhealy1:feat-catalogs-scoped-search
Open

jonhealy1 wants to merge 2 commits into
stac-utils:mainfrom
jonhealy1:feat-catalogs-scoped-search

Conversation

@jonhealy1

@jonhealy1 jonhealy1 commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Technical Context

  • Related Issues: Fixes None
  • Breaking Changes: No

Description

Adds catalog-scoped item search: GET/POST /catalogs/{catalog_id}/search, backed by CatalogsSearchExtension and AsyncCatalogsSearchClient from stac-fastapi-catalogs-extension>=1.1.0 (already the required version). Enabled automatically whenever ENABLE_CATALOGS_EXTENSION is on — no additional flag, matching how SFEOS wires it.

How it works

  • CatalogsClient now also implements AsyncCatalogsSearchClient. Both scoped endpoints bound the search to the catalog's descendant tree: catalog_search_get/catalog_search_post intersect the caller's collections filter with get_all_descendant_collection_ids, then delegate to CoreCrudClient.get_search/post_search.
  • The extension reuses the dynamic GET/POST request models built for global /search, so every enabled search extension (CQL2 filter, sort, fields, free text, token pagination) applies to scoped searches too.
  • Descendant discovery is a single recursive WITH RECURSIVE query over content->'parent_ids' in CatalogsDatabaseLogic — UNION dedup keeps poly-hierarchies correct and guarantees termination.
  • One CatalogsClient instance is shared by CatalogsExtension, CatalogsTransactionExtension, and CatalogsSearchExtension (same pattern as SFEOS): Extensions.catalog_search constructs it with core_client injected, Extensions.catalog reuses it — evaluated in that order in instantiate_api.

Semantics worth noting

  • collections omitted or [] → the catalog's full scope (same as /search treating [] as "no constraint").
  • collections partially or fully out of scope → silently intersected; an empty result returns 200 with features: [] — a filter that matches nothing, not an error.
  • An empty scope (e.g. a catalog with no descendant collections) must not reach get_search: clean_search_args strips empty lists, which would silently turn the request into an unbounded global /search. Both endpoints short-circuit to an empty ItemCollection instead.
  • Unknown catalog → 404 (validated inside the descendant walk).
  • The self link on scoped results is rewritten to /catalogs/{id}/search; paging links already derive from the request URL and stay scoped, and POST next-bodies re-run the intersection.
  • Scoped conformance URIs (item-search, multi-tenant-catalogs/search) are advertised both globally and per-catalog via app.state.catalogs_conformance_classes.

Tests

New coverage in tests/extensions/test_catalogs.py: subtree/poly-hierarchy traversal, GET↔POST parity, collections intersection (in-scope, mixed, [], fully out-of-scope), 404 on unknown catalog, empty-catalog with out-of-scope items seeded (regression test for the scope-escape bug), passthrough of bbox/datetime/ids/limit/sortby/cql2, invalid datetime → 400, scoped self link, and conformance advertising.

Verification

  • pytest tests/ (docker, pgstac 0.9.12 + 0.10.0): 3112 passed, 6 xfailed
  • pre-commit run --all-files: isort, ruff, ruff-format, mypy all clean

Checklist

  • Linting: Code is formatted and linted
  • Tests: Tests pass. I have included new tests for these changes where applicable.
  • Edge Cases: I have manually verified "unhappy paths" and edge cases beyond the basic success criteria (e.g., database connection timeouts, malformed input, strict mapping rejections).
  • Documentation: I have updated README.md to reflect any new environment variables, configuration changes, or breaking updates.
  • Accountability: I can explain the implementation logic for every line of code submitted.

AI tool usage

  • AI (Copilot or something similar) supported my development of this PR. See our policy about AI tool use. Use of AI tools must be indicated.

Policy: We require a "human-in-the-loop." You are the author and are fully accountable for all submitted code. Please ensure all tool-generated content is thoroughly reviewed before submission to ensure it is not an "extractive contribution" that squanders maintainer time.

jonhealy1 and others added 2 commits November 20, 2026 14:39
Implements AsyncCatalogsSearchClient and wires CatalogsSearchExtension so
GET/POST /catalogs/{catalog_id}/search search items bounded to a catalog's
descendant tree. Descendant collections are resolved with a single
recursive CTE over collections.content->'parent_ids' (UNION dedupes
poly-hierarchy paths and guarantees termination). Explicit `collections`
parameters are intersected with the allowed scope; fully out-of-scope
requests return 403 and unknown catalogs 404.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…ndling

Adds GET/POST /catalogs/{catalog_id}/search endpoints that search items within a catalog's descendant tree. The scoped search delegates to the core client with an intersected collections filter. Empty-scope requests (all requested collections outside the catalog or an empty catalog) return an empty ItemCollection instead of errors. The self link in scoped results references the scoped route rather than global /search.
@jonhealy1 jonhealy1 changed the title Feat: catalogs scoped search feat: catalogs scoped search Nov 20, 2026
@jonhealy1
jonhealy1 marked this pull request as ready for review November 21, 2026 03:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants