Skip to content

wip: locations endpoint#1767

Open
cka-y wants to merge 7 commits into
mainfrom
feat/loc-hierarchy
Open

wip: locations endpoint#1767
cka-y wants to merge 7 commits into
mainfrom
feat/loc-hierarchy

Conversation

@cka-y

@cka-y cka-y commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Summary:
Closes https://github.com/MobilityData/product-tasks/issues/202
This pull request introduces a new /locations API endpoint for searching locations in the Mobility Database, along with the associated backend implementation, OpenAPI documentation, and tests. It also includes minor improvements to the database utility functions and code organization.

The most important changes are:

New Locations API Endpoint

  • Added OpenAPI specification for /v1/locations with parameters for search query, country code, subdivision code, location type, and pagination; response includes total count and results. [1] [2] [3]
  • Registered the new locations tag and endpoint in the API generator and FastAPI application. [1] [2] [3] [4] [5]

Backend Implementation

  • Implemented LocationsApiImpl in locations_api_impl.py, supporting full-text search (with typeahead), filtering, normalization, and paginated results from the geopolygon materialized view.

Testing

  • Added comprehensive unit tests for all helper functions and the main endpoint logic in test_locations_api_impl.py.

Supporting Changes

  • Added new generated model files for LocationSearchResponse and LocationSearchResult.
  • Improved the unaccent SQL function to support caching in SQLAlchemy.

These changes collectively add a robust, well-documented, and tested location search capability to the API.
Please make sure these boxes are checked before submitting your pull request - thanks!

  • Run the unit tests with ./scripts/api-tests.sh to make sure you didn't break anything
  • Add or update any needed documentation to the repo
  • Format the title like "feat: [new feature short description]". Title must follow the Conventional Commit Specification(https://www.conventionalcommits.org/en/v1.0.0/).
  • Linked all relevant issues
  • Include screenshot(s) showing how this pull request works and fixes the issue(s)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new /v1/locations search capability to the Mobility Feed API, backed by a new geopolygon-based materialized view/read-model and populated/maintained via the reverse-geolocation population workflow.

Changes:

  • Introduces /v1/locations in the OpenAPI spec and wires the generated router into the FastAPI app.
  • Adds backend query implementation for location search (FTS + filters + pagination) and unit tests.
  • Adds Liquibase migrations for a GeopolygonHierarchy table plus a GeopolygonLocationSearch materialized view and indexes; updates the reverse-geolocation populate function to maintain/refresh this read model.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
liquibase/materialized_views/materialized_views.xml Adds rebuild step for the new location-search materialized view.
liquibase/materialized_views/geopolygon_location_search.sql Defines GeopolygonLocationSearch MV and related indexes for search.
liquibase/changes/feat_pt_202.sql Adds GeopolygonHierarchy table used to resolve parent/country/subdivision relationships.
liquibase/changelog.xml Ensures the hierarchy table is created before materialized views are rebuilt.
functions-python/reverse_geolocation_populate/src/main.py Updates the populate workflow to upsert hierarchy edges and refresh the MV.
functions-python/reverse_geolocation_populate/tests/test_reverse_geolocation_populate.py Adds unit coverage for hierarchy update + MV refresh hooks.
docs/DatabaseCatalogAPI.yaml Adds /v1/locations endpoint and new response/result schemas + limit parameter.
api/src/feeds/impl/locations_api_impl.py Implements the location search query logic against the MV.
api/tests/unittest/test_locations_api_impl.py Adds unit tests for helpers and get_locations behavior.
api/src/shared/database/sql_functions/unaccent.py Enables SQLAlchemy caching for the unaccent SQL function wrapper.
api/src/main.py Registers the new locations router.
api/.openapi-generator/FILES Updates the generated-file manifest for new locations API/models.

Comment thread functions-python/reverse_geolocation_populate/src/main.py
Comment on lines +251 to +254
locality's representative point is computed once, and containment is tested with
``ST_Covers`` against the raw (spatially indexed) candidate geometry. Point-in-
polygon is robust to invalid polygons, so the large candidate geometries are
never repaired with ``ST_MakeValid`` here.
Comment thread liquibase/changes/feat_pt_202.sql
Comment thread liquibase/materialized_views/geopolygon_location_search.sql
Comment thread liquibase/materialized_views/geopolygon_location_search.sql
Comment thread liquibase/materialized_views/geopolygon_location_search.sql
Comment thread liquibase/materialized_views/geopolygon_location_search.sql
Comment thread liquibase/materialized_views/geopolygon_location_search.sql
@cka-y
cka-y marked this pull request as ready for review July 20, 2026 19:57
"""

pass
inherit_cache = True

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixes unaccent warning in logs

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