mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-01 00:43:15 +00:00
fix(maps): keep residential listings out of sights
The Overture historic-site category includes residential listings. Omit those listings from sights while preserving explicitly historic places and the existing provider fallback. Closes #3270
This commit is contained in:
@@ -136,7 +136,10 @@ function packTerms(terms: readonly string[]): string[] {
|
||||
export function indexRequests(plan: IndexPoiPlan): IndexRequest[] {
|
||||
const all = plan.terms.join(',');
|
||||
if (plan.cap <= INDEX_MAX_LIMIT && all.length <= INDEX_MAX_CATEGORY_CHARS) {
|
||||
return [{ category: all, limit: plan.cap }];
|
||||
// Give sights room for historic-site rows that turn out to be housing.
|
||||
const limit =
|
||||
plan.wanted.length === 1 && plan.wanted[0] === 'sights' ? Math.min(INDEX_MAX_LIMIT, plan.cap * 2) : plan.cap;
|
||||
return [{ category: all, limit }];
|
||||
}
|
||||
return indexRequestsPerKind(plan);
|
||||
}
|
||||
@@ -199,7 +202,8 @@ export function indexPoiAnswer(
|
||||
): PoiSearchResult {
|
||||
const { wanted, labelFor, cap, radius, reach } = plan;
|
||||
// Pages asked per category can together run past the cap.
|
||||
const kept = belonging(found, plan).slice(0, cap);
|
||||
const matching = belonging(found, plan);
|
||||
const kept = matching.slice(0, cap);
|
||||
return {
|
||||
pois: kept.map((p) => ({
|
||||
osm_id: `gers:${p.gers}`,
|
||||
@@ -233,13 +237,17 @@ export function indexPoiAnswer(
|
||||
// The page the index sent, not what was left of it: a full page means more
|
||||
// places, however many of them this one had to leave out. Pages asked per
|
||||
// category say so for themselves, and their sum may run past the cap.
|
||||
truncated: pageFull || found.length > cap,
|
||||
truncated: pageFull || matching.length > cap,
|
||||
// A wide viewport is narrowed here too, and the caller is told so
|
||||
// for the same reason the Overpass path tells it.
|
||||
clamped: radius < reach,
|
||||
};
|
||||
}
|
||||
|
||||
const RESIDENTIAL_SITE_SUFFIX = /\b(?:apartments?|apts\.?|apartment homes|condos?|condominiums?|condo association)$/i;
|
||||
const PUBLIC_SITE_NAME = /\b(?:historic|heritage|museum|landmark)\b/i;
|
||||
const HISTORIC_SITE_TERM = 'cultural_and_historic>historic_site';
|
||||
|
||||
/**
|
||||
* The rows that belong to a pill the request asked for. The index matches its
|
||||
* terms inside the category text, so a near miss can still come back, and it
|
||||
@@ -247,9 +255,16 @@ export function indexPoiAnswer(
|
||||
* be told either way and stays, as it always has.
|
||||
*/
|
||||
export function belonging<T extends TrekPlace & { categoryPath?: string | null }>(found: T[], plan: IndexPoiPlan): T[] {
|
||||
return found.filter(
|
||||
(p) => (!p.category && !p.categoryPath) || plan.labelFor(p.category ?? null, p.categoryPath ?? null) !== undefined,
|
||||
);
|
||||
return found.filter((place) => {
|
||||
const leaf = place.category ?? null;
|
||||
const path = place.categoryPath ?? null;
|
||||
const category = plan.labelFor(leaf, path);
|
||||
if (category === 'sights' && place.source === 'overture' && indexRowTerm([HISTORIC_SITE_TERM], leaf, path)) {
|
||||
// Overture labels some residential buildings as historic sites (#3270).
|
||||
if (RESIDENTIAL_SITE_SUFFIX.test(place.name.trim()) && !PUBLIC_SITE_NAME.test(place.name)) return false;
|
||||
}
|
||||
return category !== undefined || (!leaf && !path);
|
||||
});
|
||||
}
|
||||
|
||||
const regionNamesByLang = new Map<string, Intl.DisplayNames | null>();
|
||||
|
||||
@@ -161,6 +161,30 @@ beforeEach(() => {
|
||||
});
|
||||
|
||||
describe('MapsService.pois answered from the index', () => {
|
||||
it('MAPS-POIS-019: residential rows mislabeled as historic sites do not consume the sights list', async () => {
|
||||
const historicSite = {
|
||||
...FULL,
|
||||
category: 'historic_site',
|
||||
categoryPath: 'cultural_and_historic>historic_site',
|
||||
confidence: 0.99,
|
||||
};
|
||||
const results = [
|
||||
{ ...historicSite, gers: 'housing', name: 'Pisgah View Apartments' },
|
||||
{ ...historicSite, gers: 'condos', name: 'The Landings Condos', category: null },
|
||||
{ ...historicSite, gers: 'museum', name: 'Museum of Historic Apartments' },
|
||||
{ ...historicSite, gers: 'estate', name: 'Biltmore Estate', confidence: 0.8 },
|
||||
];
|
||||
mockNearby.mockImplementation(async (_lat, _lng, options) => results.slice(0, options?.limit));
|
||||
const svc = make();
|
||||
const overpass = stubOverpass(svc);
|
||||
|
||||
const answer = await svc.pois('sights', BOX, undefined, 3);
|
||||
|
||||
expect(overpass).not.toHaveBeenCalled();
|
||||
expect(answer.pois.map((poi) => poi.name)).toEqual(['Museum of Historic Apartments', 'Biltmore Estate']);
|
||||
expect(answer.truncated).toBe(false);
|
||||
});
|
||||
|
||||
it('MAPS-POIS-001: maps a full index row onto the record the map already reads', async () => {
|
||||
mockNearby.mockResolvedValue([FULL]);
|
||||
const svc = make();
|
||||
|
||||
Reference in New Issue
Block a user