From a39c31cb489c7aa60e7024b13061ee5c94248826 Mon Sep 17 00:00:00 2001 From: Maurice <61554723+mauriceboe@users.noreply.github.com> Date: Tue, 11 Aug 2026 17:04:09 +0200 Subject: [PATCH] Hide permanently closed places from search (#1887) A place that has shut down for good is never the answer to "where should we go", so it should not be in the results at all. Google knows this and says so in businessStatus, we just never asked for the field. It goes into the field mask and CLOSED_PERMANENTLY drops out. CLOSED_TEMPORARILY stays - a restaurant on holiday next month is still worth planning around - and results without the field are parks and viewpoints rather than businesses, so they stay too. OSM states it a few different ways. Re-tagged objects (disused:amenity, abandoned:shop) never matched the selectors to begin with, but plenty keep their original tag and gain a marker instead, and those did come back. Same for opening_hours=closed/off. --- server/src/nest/maps/maps.service.ts | 19 ++++++++-- server/tests/unit/nest/maps.service.test.ts | 40 +++++++++++++++++++++ 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/server/src/nest/maps/maps.service.ts b/server/src/nest/maps/maps.service.ts index 8a997aba9..abe08c8fc 100644 --- a/server/src/nest/maps/maps.service.ts +++ b/server/src/nest/maps/maps.service.ts @@ -260,6 +260,8 @@ export interface CommonsCandidate { interface GooglePlaceResult { id: string; displayName?: { text: string }; + /** OPERATIONAL | CLOSED_TEMPORARILY | CLOSED_PERMANENTLY. Absent on non-business results. */ + businessStatus?: string; formattedAddress?: string; location?: { latitude: number; longitude: number }; rating?: number; @@ -806,6 +808,13 @@ export class MapsService { const tags = el.tags || {}; const name = tags[`name:${osmLang}`] || tags['int_name'] || tags.name || tags.brand || null; if (!name) continue; // unnamed POIs aren't useful to add to a plan + // A shut-down place is not somewhere to plan a visit (#1341). OSM usually + // re-tags one with a `disused:`/`abandoned:` prefix, and those never match + // the selectors above — but plenty keep their original tag and gain a marker + // instead, and those do come back. `opening_hours=closed`/`off` is the same + // statement in the hours field. + if (tags.disused === 'yes' || tags.abandoned === 'yes') continue; + if (tags.opening_hours === 'closed' || tags.opening_hours === 'off') continue; const lat = el.lat ?? el.center?.lat; const lng = el.lon ?? el.center?.lon; if (lat == null || lng == null) continue; @@ -1404,7 +1413,7 @@ export class MapsService { 'Content-Type': 'application/json', 'X-Goog-Api-Key': apiKey, 'X-Goog-FieldMask': - 'places.id,places.displayName,places.formattedAddress,places.location,places.rating,places.websiteUri,places.nationalPhoneNumber,places.types,places.googleMapsUri', + 'places.id,places.displayName,places.formattedAddress,places.location,places.rating,places.websiteUri,places.nationalPhoneNumber,places.types,places.googleMapsUri,places.businessStatus', }, body: JSON.stringify(searchBody), }); @@ -1417,7 +1426,13 @@ export class MapsService { throw err; } - const places = (data.places || []).map((p: GooglePlaceResult) => ({ + // A place that has shut down for good is never the answer to "where should we + // go" (#1341). Temporarily closed stays: a restaurant on holiday next month is + // still worth planning around. Anything without the field is a non-business + // result (a park, a viewpoint) and is kept. + const places = (data.places || []) + .filter((p: GooglePlaceResult) => p.businessStatus !== 'CLOSED_PERMANENTLY') + .map((p: GooglePlaceResult) => ({ google_place_id: p.id, google_ftid: googleFtidFromMapsUrl(p.googleMapsUri), name: p.displayName?.text || '', diff --git a/server/tests/unit/nest/maps.service.test.ts b/server/tests/unit/nest/maps.service.test.ts index f31587166..3f7a5bb2b 100644 --- a/server/tests/unit/nest/maps.service.test.ts +++ b/server/tests/unit/nest/maps.service.test.ts @@ -804,6 +804,25 @@ describe('searchOverpassPois localized names (#1655)', () => { expect(pois[0].name).toBe('Elephant Obelisk'); }); + it('skips POIs tagged as closed for good (#1341)', async () => { + vi.stubGlobal( + 'fetch', + vi.fn().mockResolvedValue({ + ok: true, + json: async () => ({ + elements: [ + { type: 'node', id: 1, lat: 41.9, lon: 12.48, tags: { name: 'Gone Forever', tourism: 'attraction', disused: 'yes' } }, + { type: 'node', id: 2, lat: 41.9, lon: 12.49, tags: { name: 'Ruin', tourism: 'attraction', abandoned: 'yes' } }, + { type: 'node', id: 3, lat: 41.9, lon: 12.5, tags: { name: 'Shut', tourism: 'attraction', opening_hours: 'closed' } }, + { type: 'node', id: 4, lat: 41.9, lon: 12.51, tags: { name: 'Open For Business', tourism: 'attraction' } }, + ], + }), + }), + ); + const { pois } = await svc.searchOverpassPois('sights', bbox(5), 'en-US'); + expect(pois.map((p: any) => p.name)).toEqual(['Open For Business']); + }); + it('falls back to the native name when no localized tag exists', async () => { stubOverpass({ name: tags.name, tourism: 'attraction' }); const { pois } = await svc.searchOverpassPois('sights', bbox(4), 'fr-FR'); @@ -1162,6 +1181,27 @@ describe('searchPlaces (fetch stubbed)', () => { expect(place.phone).toBeNull(); }); + it('MAPS-183: drops permanently closed Google results and keeps the rest (#1341)', async () => { + mockDbGet.mockReturnValueOnce({ maps_api_key: 'some-key' }); + const fetchMock = vi.fn().mockResolvedValue({ + ok: true, + json: async () => ({ + places: [ + { id: 'gone', displayName: { text: 'Shuttered Bistro' }, businessStatus: 'CLOSED_PERMANENTLY' }, + { id: 'holiday', displayName: { text: 'Winter Break Cafe' }, businessStatus: 'CLOSED_TEMPORARILY' }, + { id: 'open', displayName: { text: 'Still Trading' }, businessStatus: 'OPERATIONAL' }, + { id: 'park', displayName: { text: 'City Park' } }, + ], + }), + }); + vi.stubGlobal('fetch', fetchMock); + const result = await svc.searchPlaces(1, 'bistro'); + expect(result.places.map((p: any) => p.google_place_id)).toEqual(['holiday', 'open', 'park']); + // The field has to be requested or it never arrives to filter on. + const mask = (fetchMock.mock.calls[0][1].headers as Record)['X-Goog-FieldMask']; + expect(mask).toContain('places.businessStatus'); + }); + it('MAPS-107: keeps 0 coordinates (equator / prime meridian) instead of nulling them', async () => { mockDbGet.mockReturnValueOnce({ maps_api_key: 'some-key' }); vi.stubGlobal(