Skip to content

feat(search): spatial coverage facet + exclude world from lower-level filters#1038

Merged
rdahis merged 2 commits into
stagingfrom
claude/spatial-coverage-facet
Jul 9, 2026
Merged

feat(search): spatial coverage facet + exclude world from lower-level filters#1038
rdahis merged 2 commits into
stagingfrom
claude/spatial-coverage-facet

Conversation

@rdahis

@rdahis rdahis commented Jul 9, 2026

Copy link
Copy Markdown
Member

Summary

Two changes to the /search endpoint that back the website's spatial-coverage filter (basedosdados/website#1594).

  1. Add spatial_coverages to the aggregations. get_facets() never emitted a spatial-coverage bucket list, so the website filter had nothing to seed from. Mirrors the existing organizations facet: request the spatial_coverage facet and translate slugs via Area (name_{locale}). Output shape matches the other facets: [{key, count, name, fallback}]. The index field, ?spatial_coverage=<slug> filtering, per-result output, and /facet_values/ already existed on staging.
  2. Exclude world from lower-level spatial filters. Selecting a specific area OR'd in spatial_coverage_exact:"world", so filtering by Brazil returned Brazil-only datasets plus every global dataset (e.g. 294 → 673). Global datasets are indexed as ["world"] only (get_spatial_coverage), so the facet counts were already mutually exclusive; this aligns the filter results with them. Ancestor rollup is preserved (a state still matches its country); only world is dropped.

Test plan

Verified against a local stack (Elasticsearch + fixtures, rebuild_index):

  • /search aggregations now include spatial_coverages (world, br, us, …) with correct localized names and counts.
  • ?spatial_coverage=br294 (was 673); ?spatial_coverage=world → 379; ?spatial_coverage=us → 175 (no world leak); ?spatial_coverage=br_sp → 306 (São Paulo 12 + country rollup 294, no world).

Not included here

The world Area rename to "International"/"Internacional" is a data change (updates the Area row's name/name_{locale}; the slug stays world because it's hardcoded in the filter logic and used at index time). It resolves at query time, so no reindex is needed — apply it directly on the target DB (or as a data migration) rather than via this code PR.

🤖 Generated with Claude Code

rdahis and others added 2 commits July 9, 2026 21:52
Mirror the organizations facet in get_facets() so /search/ returns a
spatial_coverages bucket list ({key,count,name,fallback}); the website
search filter seeds its choices from this aggregation.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Selecting a specific area (e.g. br) OR'd in spatial_coverage_exact:"world",
so filtering by Brazil returned Brazil-only datasets plus every global
("world") dataset (294 -> 673). Global datasets are indexed as ["world"]
only (get_spatial_coverage), so the facet counts were already exclusive;
this aligns the filter results with them. Ancestor rollup is preserved
(a state still matches its country); only world is dropped.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@mergify

mergify Bot commented Jul 9, 2026

Copy link
Copy Markdown

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

@rdahis rdahis self-assigned this Jul 9, 2026
@rdahis rdahis merged commit f892d70 into staging Jul 9, 2026
5 checks passed
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.

1 participant