Skip to content

Search route short and long names in routes-for-location query - #1289

Open
ARCoder181105 wants to merge 6 commits into
OneBusAway:mainfrom
ARCoder181105:routes-for-location-query-search
Open

Search route short and long names in routes-for-location query#1289
ARCoder181105 wants to merge 6 commits into
OneBusAway:mainfrom
ARCoder181105:routes-for-location-query-search

Conversation

@ARCoder181105

@ARCoder181105 ARCoder181105 commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

Summary

query only matched routes.short_name exactly, so long-name-only
matches (e.g. "Shasta View/Shasta College") never worked. Now searches
both short and long names via the existing routes_fts index, ranked
by relevance, then filtered to routes with a stop in bounds.

  • Reuse routes_fts / Manager.SearchRoutes for the candidate lookup
  • Fix punctuation-only terms (e.g. %) crashing FTS5 instead of matching nothing
  • Drop unused queryTime param from GetRoutesForLocation

Fixes #1228

Note for reviewer

Verified against api.pugetsound.onebusaway.org: the real server does
exact-token matching (query=Rap → 0 results, needs Rap*). This PR
always does prefix matching (query=Ro matches "Roosevelt" routes, no
* needed) — kept intentionally, better for live search. Flagging, not
filing as a defect.

Test plan

  • go vet (both build tags), make test, go fmt
  • New tests: long-name match, prefix match, multi-word AND, no-match,
    candidate cap, out-of-bounds text match
  • Manually verified against live King County Metro feed vs prod

Summary by CodeRabbit

  • New Features

    • Route searches now support text queries, including multi-term matching and long route names.
    • Search results can be filtered by geographic bounds.
    • Results are limited to the requested maximum count.
  • Bug Fixes

    • Punctuation-only searches no longer produce errors.
    • Improved handling when no matching routes are found.
  • Tests

    • Added coverage for route matching, geographic filtering, result limits, and punctuation-only input.

FTS5 tokenizes a term like "%" to nothing, which raises a syntax
error at MATCH time instead of just matching zero rows. Filter such
terms out before building the query so they collapse to a no-op
search, matching how extractFTS5Terms already handles this in the
stop search handler. Extracted the shared predicate into
utils.ContainsLetterOrDigit so both call sites use one definition.
routes-for-location's query param only matched routes.short_name via
exact equality, so a query like "Shasta" never matched a route whose
name only appears in long_name (e.g. "Shasta View/Shasta College").
The spec requires searching a text index of both short and long
names, considering at most maxCount+1 candidates by relevance before
filtering to those with a stop in bounds.

Reuse the existing routes_fts index (Manager.SearchRoutes) for the
ranked candidate lookup, then filter GetActiveRoutesWithinBounds to
just those candidate route IDs instead of an exact short_name match.
An empty candidate set must short-circuit before reaching the bounds
query, since an empty RouteIDs filter there means "no filter" and
would otherwise return every in-bounds route regardless of query.

Also drop GetRoutesForLocation's queryTime parameter, which the
function never read; it's the same call site being touched by the
signature change above.
Add handler tests for the new text-search path: matching a route by
long name only, a prefix token, ANDed multi-word queries, a query
with no matching route text, candidates truncated at maxCount+1, and
a text match whose stops fall outside the search bounds (still
excluded). Existing exact short-name, case-insensitive, and literal
wildcard tests already covered the prior behaviour and needed no
changes.
@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@ARCoder181105, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 38 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: bb7bedae-bdf4-4bc7-b1fb-eef0c267d615

📥 Commits

Reviewing files that changed from the base of the PR and between e476c83 and 1a4e092.

📒 Files selected for processing (1)
  • gtfsdb/stops_rtree.go
📝 Walkthrough

Walkthrough

The location route search now uses text-indexed route candidates, filters candidates by geographic bounds, and supports dynamic route-ID SQL filtering. Shared term validation prevents punctuation-only FTS5 queries from causing errors.

Changes

Route location search

Layer / File(s) Summary
Search term validation
internal/utils/string_utils.go, internal/gtfs/route_search.go, internal/restapi/search_stops_handler.go, internal/gtfs/route_search_test.go
Adds ContainsLetterOrDigit and uses it to exclude punctuation-only FTS5 terms. Adds regression coverage.
Dynamic route-ID bounds query
gtfsdb/stops_rtree.go
Replaces short-name filtering with optional route-ID filtering. The SQL template and bind positions adjust for the number of route IDs.
Text and geographic search orchestration
internal/gtfs/gtfs_manager.go, internal/restapi/routes_for_location_handler.go, internal/restapi/routes_for_location_handler_test.go
Searches route candidates before geographic filtering. Updates the API call and tests for matching, limits, no results, and radius filtering.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related PRs

Suggested reviewers: fletcherw, ahmedhossamdev, burma-shave

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 37.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: converting the routes-for-location query from short-name-only exact matching to searching both short and long names using text search.
Linked Issues check ✅ Passed All requirements from issue #1228 are met: the implementation searches both short and long names via FTS5 index, uses text-based matching instead of exact matching, ranks by relevance, considers maxCount + 1 candidates, and filters by geographic bounds.
Out of Scope Changes check ✅ Passed All changes directly support the core objective. The utility helper, punctuation filtering, and handler updates all address FTS5 safety or API consistency required for the search functionality.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@gtfsdb/stops_rtree.go`:
- Around line 168-179: Add Go doc comments in gtfsdb/stops_rtree.go for exported
GetActiveRoutesWithinBoundsParams and GetActiveRoutesWithinBounds, with each
comment beginning with its identifier. In internal/gtfs/gtfs_manager.go, update
the GetRoutesForLocation doc comment so it begins with GetRoutesForLocation.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: c4bb3756-a436-4d17-9342-55887def5990

📥 Commits

Reviewing files that changed from the base of the PR and between 3b73fd9 and e476c83.

📒 Files selected for processing (8)
  • gtfsdb/stops_rtree.go
  • internal/gtfs/gtfs_manager.go
  • internal/gtfs/route_search.go
  • internal/gtfs/route_search_test.go
  • internal/restapi/routes_for_location_handler.go
  • internal/restapi/routes_for_location_handler_test.go
  • internal/restapi/search_stops_handler.go
  • internal/utils/string_utils.go

Comment thread gtfsdb/stops_rtree.go
golint requires exported identifiers' doc comments to start with
their own name; GetActiveRoutesWithinBoundsParams and
GetActiveRoutesWithinBounds had none.

@Ahmedhossamdev Ahmedhossamdev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hey @ARCoder181105, Great work on this.

I verified the long-name search against the live Unitrans Java server and it checks out. The punctuation-only FTS5 fix and the ContainsLetterOrDigit extraction are clean. LGTM, one optional note on the dynamic SQL inline. Lint and all tests pass.

Comment thread gtfsdb/stops_rtree.go
The IN clause is assembled with fmt.Sprintf, which reads as
concatenated SQL. Record that only generated "?N" placeholders are
formatted into the query text and route IDs travel as bind values.
@sonarqubecloud

sonarqubecloud Bot commented Aug 5, 2026

Copy link
Copy Markdown

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.

routes-for-location: Query parameter only searches route short names

2 participants