Skip to content

fix(places): OR-match multi-value categories in find_nearby_places - #52

Open
asem89 wants to merge 1 commit into
NERVsystems:mainfrom
asem89:fix/nearby-places-multivalue-or
Open

asem89 wants to merge 1 commit into
NERVsystems:mainfrom
asem89:fix/nearby-places-multivalue-or

Conversation

@asem89

@asem89 asem89 commented Jun 23, 2026

Copy link
Copy Markdown

Problem

find_nearby_places returns {"places":[]} for any category that maps to multiple OSM tag values — which includes most of the common ones (restaurant, cafe, healthcare, finance, transport, ...). It reproduces everywhere, including dense city centers, so the tool effectively can't find restaurants at all.

Root cause

The handler builds the Overpass query by calling WithTag(key, value) once per value:

for key, values := range osmTags {
    for _, value := range values {
        queryBuilder.WithTag(key, value)
    }
}

Each WithTag appends a separate tag filter, and buildElementFilter concatenates them, so they are AND-ed:

node(around:2000,...)[amenity=restaurant][amenity=cafe][amenity=fast_food][amenity=bar][amenity=pub][amenity=food_court];

No single element can have amenity equal to six values at once, so the result set is always empty.

Fix

Pass all values for a key in one variadic WithTag(key, values...) call. The builder's existing multi-value path then emits the intended OR-regex — and this matches the usage example already documented in pkg/core/overpass.go (WithTag("amenity", "restaurant", "cafe")):

node(around:2000,...)[amenity~"restaurant|cafe|fast_food|bar|pub|food_court"];

Verification (manual, against live Overpass via the MCP server)

find_nearby_places{category:"restaurant"}:

Location Before After
Gdańsk old town (54.3486, 18.6536, r=800) 0 6 (Hard Rock Cafe, Piwnica Rajców, …)
Gdańsk / Stogi (54.3629, 18.7083, r=3000) 0 6 (Bar Caira, ControlFood, …)

Single-value categories (e.g. pharmacy) were unaffected before and after.

find_nearby_places called WithTag(key, value) once per value, producing
AND-matched filters like [amenity=restaurant][amenity=cafe][amenity=bar]...
A single element can never hold all those values at once, so every
multi-value category (restaurant, cafe, healthcare, finance, transport, ...)
returned an empty {"places":[]} result regardless of location.

Pass all values in one WithTag(key, values...) call so the builder emits
the intended OR-regex [amenity~"restaurant|cafe|..."], matching the usage
example documented in pkg/core/overpass.go.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c2e16f2842

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread pkg/tools/places.go
for _, value := range values {
queryBuilder.WithTag(key, value)
}
queryBuilder.WithTag(key, values...)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge OR categories across tag keys as well

When the requested category maps to more than one OSM key, this still appends every key to the same global tag set, and OverpassBuilder.buildElementFilter concatenates those filters into one selector (pkg/core/overpass.go:218-220). For example category:"cafe" now emits filters like [amenity~"cafe|ice_cream"][shop~"coffee|tea"], requiring an element to have both tags, while mapCategoryToOSMTags defines those keys as alternatives (pkg/tools/places.go:258-262); the same applies to park, pharmacy, transport, and unknown multi-word categories, so those searches remain empty or severely underreported unless an object happens to carry all tag families.

Useful? React with 👍 / 👎.

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