Derive LocationType from the primary Google type for keyword searches - #452
Merged
Conversation
Keyword (brand) searches query Google with LocationTypeAny, so
parsePlacesSearchResponse stamped every result with LocationType "".
The write path is a blind upsert into the shared placeDetails:{id}
records that category reads hydrate from, so each brand search wiped
the type off previously typed records — a McDonald's cached by an
Eatery search was then served with no type, and downstream consumers
(OfferBee best-card) scored it at base rate instead of dining.
Two changes, both gap-filling only:
- parsePlacesSearchResponse: when the searched type is LocationTypeAny,
derive LocationType from POI.PrimaryLocationType(place.Types) — the
same machinery ReclassifyForCategory already uses on category reads.
Typed searches keep their searched-type stamp.
- restoreCachedDetails: restore the stored LocationType when the
rebuilt record has none, same "fill a gap, never overwrite" rule as
URL/Summary/Address/Hours.
Existing blank-typed records stay blank until a fresh search rewrites
them; this stops new wipes and types new keyword results at the source.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011BmBJ2x6b7V36vywSMrYDy
Ronnie434
approved these changes
Aug 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Keyword (brand) searches (
/v1/nearby-places) query Google withLocationTypeAny, andparsePlacesSearchResponsestamps every result with the searched type — so keyword results are cached withLocationType: "". The write path (SetPlacesAddGeoLocationsForBrand) is a blind upsert into the sharedplaceDetails:{id}records that category reads hydrate from, andrestoreCachedDetailsrestores URL/Summary/Address/Hours but not LocationType. Net effect: every brand search wipes the type off previously typed records.Observed downstream (OfferBee staging): a McDonald's row cached by an Eatery category search was served with
LocationType: ""after brand searches rewrote its record, so the best-card ranking scored every card at its base rate — Chase Sapphire Reserve showed 1X at McDonald's instead of 3X dining.Fix (both changes gap-filling only)
parsePlacesSearchResponse: when the searched type isLocationTypeAny, deriveLocationTypefromPOI.PrimaryLocationType(place.Types)— the same machineryReclassifyForCategoryalready uses to re-tag places on category reads (Classify category-endpoint places by primary Google type #442). Google lists the most specific type first and umbrella types (food,point_of_interest, …) are skipped, so a McDonald's (["meal_takeaway", "food", ...]) comes outmeal_takeaway. Typed searches keep their searched-type stamp — re-tagging those staysReclassifyForCategory's job.restoreCachedDetails: restore the storedLocationTypewhen the rebuilt record has none — same "only ever fills a gap, never overwrites" rule the function already documents for the Details-sourced fields. Covers keyword results whoseTypescarry no meaningful primary.Safety
SetPlacesAddGeoLocationsalready refuses unmapped types ("Refuse to guess a bucket").Types→PrimaryLocationTypereturns""→ identical to today.Testing
TestParsePlacesSearchResponseKeywordDerivesLocationType(keyword derives from Types; umbrella-only stays blank; typed search stamp unchanged),TestRestoreCachedDetailsPreservesLocationType(untyped rebuild recovers stored type; fresh type never overwritten). Both watched fail before the fix.go build ./... && go vet ./iowrappers/ && go test ./...all green.🤖 Generated with Claude Code
https://claude.ai/code/session_011BmBJ2x6b7V36vywSMrYDy