Implementation Plan - Search Revamp & Discovery
Mapping implementation: The mapping follow-up plan defines the delivered MapLibre GL JS integration and bounded SQL map endpoints. It reuses current search predicates and requires no new geometry columns, spatial extension, or migration.
Technical Architecture
1. Data Layer (backend/packages/db)
- Create an Alembic migration:
- Add
pg_trgmextension if not exists. - Add columns to
searchtable:city,state,country,latitude,longitude,reservable,campsite_types,has_electric,has_water,has_sewer,pets_allowed,ada_accessible,max_rv_length,search_vector. - Add GIN indexes on
search_vector,campground_name(trgm),recreation_area_name(trgm), and composite index on(latitude, longitude).
- Add
- Update
SearchORM model inbackend/packages/db/db/models/search.py. - Update SQL insert statements in
BaseProvider(backend/packages/providers/providers/base.py) to map these columns when populating the search table fromRecreationAreaandCampground.
2. Provider Ingestion (backend/packages/providers)
- Ensure
RecreationGovProviderpopulates campground and rec area city, state, country, lat/long, and amenities intoCampgroundandRecreationAreatables. - Update
BaseProvider.populate_search_tableto include the enriched attributes.
3. API & Search Engine (backend/packages/backend)
- Modernize
Search.algorithmindb.models.search:- Build composable query filters:
- Text query: Trigram matching + Full-text search ranking.
- State filter:
cls.state.ilike(...)orin_(states). - Provider filter:
cls.provider_id.in_(provider_ids). - Campsite types: JSONB / array contains check.
- Amenity filters:
has_electric,pets_allowed,max_rv_length >= min_rv_length. - Geospatial radius: Haversine distance formula calculation.
- Compute faceted aggregation counts efficiently.
- Build composable query filters:
- Update
backend/packages/backend/backend/routers/search.py:- Support both
queryandq, pagination params (page,page_size), and filter params. - Return
SearchResultResponseor richSearchResponse(with backward compatibility).
- Support both
- Regenerate API client types via
task api:generate.
4. Frontend UI/UX (frontend/src)
- Add
/searchroute infrontend/src/App.tsx. - Create
SearchPage.tsxwith:- Filter sidebar (State selector, Campsite types, Amenities, RV length).
- Search results grid with rich
CampgroundCards. - Interactive map (using MapLibre GL JS / OpenStreetMap tiles for zero-API-key self-hosting).
- Update
SearchBar.tsx:- Handle keyboard
Enterto navigate to/search?q=.... - Keep responsive autocomplete dropdown for quick navigation.
- Handle keyboard
- Upgrade
ScanForm.tsxto pre-select campground from search result cards and map pins.
5. Verification & Testing
- Unit tests for DB models, migrations, and search algorithm (
backend/packages/db/tests,backend/packages/backend/tests). - Frontend component tests for
/search,SearchBar, andScanForm(frontend/src/test). - Full quality gates:
task test,task check,task lint.