mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-21 06:26:26 +00:00
feat(places): send a search to Google, once or always
Since 4.3.0 the TREK index and OpenStreetMap answer every search first and Google is only asked when they find nothing, so a list with the wrong place on it never reached Google, whatever key the instance had, and the provider choice only decided who fills the empty case. Two ways to change that, both only where Google holds the key slot. Under a result list that did not come from Google, one quiet line sends the same query to Google Places alone (`provider: 'google'` on the search contract, the MCP search tool takes it too). And beside the key, an admin switch "Search with Google only" hands every search and every suggestion to Google and asks nothing of the index or OpenStreetMap; off by default, read by the search after the keyed provider so an install without a key, or one on Amap or OpenStreetMap, is untouched. The panel says so beside the switch. Both shells share the one rule for when the line is offered (placeSource), and the wiki names both switches.
This commit is contained in:
@@ -18,18 +18,24 @@ describe('mapsSearchRequestSchema', () => {
|
||||
expect(mapsSearchRequestSchema.safeParse({}).success).toBe(false);
|
||||
});
|
||||
|
||||
it('takes "google" as the one provider a search can be sent to alone, and nothing else', () => {
|
||||
expect(mapsSearchRequestSchema.safeParse({ query: 'berlin', provider: 'google' }).success).toBe(true);
|
||||
expect(mapsSearchRequestSchema.safeParse({ query: 'berlin', provider: 'osm' }).success).toBe(false);
|
||||
expect(mapsSearchRequestSchema.safeParse({ query: 'berlin', provider: '' }).success).toBe(false);
|
||||
});
|
||||
|
||||
it('allows an optional circle locationBias with numeric lat/lng and optional radius', () => {
|
||||
expect(
|
||||
mapsSearchRequestSchema.safeParse({ query: 'berlin', locationBias: { lat: 52.5, lng: 13.4 } }).success,
|
||||
).toBe(true);
|
||||
expect(mapsSearchRequestSchema.safeParse({ query: 'berlin', locationBias: { lat: 52.5, lng: 13.4 } }).success).toBe(
|
||||
true,
|
||||
);
|
||||
expect(
|
||||
mapsSearchRequestSchema.safeParse({ query: 'berlin', locationBias: { lat: 52.5, lng: 13.4, radius: 50000 } })
|
||||
.success,
|
||||
).toBe(true);
|
||||
// NaN arrives as null over JSON; either way a non-numeric lat must fail.
|
||||
expect(
|
||||
mapsSearchRequestSchema.safeParse({ query: 'berlin', locationBias: { lat: null, lng: 13.4 } }).success,
|
||||
).toBe(false);
|
||||
expect(mapsSearchRequestSchema.safeParse({ query: 'berlin', locationBias: { lat: null, lng: 13.4 } }).success).toBe(
|
||||
false,
|
||||
);
|
||||
expect(mapsSearchRequestSchema.safeParse({ query: 'berlin', locationBias: { lat: 52.5 } }).success).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -172,8 +178,12 @@ describe('mapsPlaceEnrichmentResultSchema', () => {
|
||||
).toBe(true);
|
||||
// Google's search results carry a rating but no count.
|
||||
expect(
|
||||
mapsPlaceEnrichmentResultSchema.safeParse({ photos: [], description: null, facts: [], rating: { value: 4, count: null } })
|
||||
.success,
|
||||
mapsPlaceEnrichmentResultSchema.safeParse({
|
||||
photos: [],
|
||||
description: null,
|
||||
facts: [],
|
||||
rating: { value: 4, count: null },
|
||||
}).success,
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
|
||||
@@ -26,6 +26,13 @@ export const mapsSearchRequestSchema = z.object({
|
||||
// foreign-region queries. z.number() is finite-only (zod v4), matching the
|
||||
// legacy Number.isFinite() check; radius was never validated beyond "number".
|
||||
locationBias: latLng.extend({ radius: z.number().optional() }).optional(),
|
||||
/**
|
||||
* Ask one provider alone for this search. The index and OpenStreetMap answer
|
||||
* first by default and Google is only asked when they find nothing; a caller
|
||||
* whose results were not the place they meant can send the same query to
|
||||
* Google instead. Ignored on an instance where Google holds no key.
|
||||
*/
|
||||
provider: z.enum(['google']).optional(),
|
||||
});
|
||||
export type MapsSearchRequest = z.infer<typeof mapsSearchRequestSchema>;
|
||||
|
||||
@@ -39,7 +46,10 @@ export const mapsAutocompleteRequestSchema = z.object({
|
||||
* characters; anything else is dropped rather than forwarded, so a bad token
|
||||
* degrades to per-request billing instead of failing the search.
|
||||
*/
|
||||
sessionToken: z.string().regex(/^[A-Za-z0-9_-]{1,36}$/).optional(),
|
||||
sessionToken: z
|
||||
.string()
|
||||
.regex(/^[A-Za-z0-9_-]{1,36}$/)
|
||||
.optional(),
|
||||
});
|
||||
export type MapsAutocompleteRequest = z.infer<typeof mapsAutocompleteRequestSchema>;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user