mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-04 02:14:01 +00:00
fix(geocode): a region match takes the place itself, not a name starting with it
A name that only started with the place word also matched, so from Lyon "Paris, France" picked "Paris Gare de Lyon" in the biased pass, where main fell through to the unbiased answer and reached Paris. Only an exact name matches now. Adds a test for the UK alias. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
5ef78b975c
commit
7775f6007d
2 files changed
+51
-1
No files matched your search
@@ -294,7 +294,9 @@ export function selectQualifiedFeature(features, query) {
|
||||
(Array.isArray(features) ? features : []).find((feature) => {
|
||||
const properties = feature?.properties ?? {};
|
||||
const name = normalizeToponym(properties.name);
|
||||
if (name !== head && !name.startsWith(`${head} `)) return false;
|
||||
// Exactly the place: "Paris Gare de Lyon" is in France too, but it
|
||||
// is not what "Paris, France" asks for.
|
||||
if (name !== head) return false;
|
||||
const where = ` ${normalizeToponym(
|
||||
[
|
||||
properties.city,
|
||||
|
||||
@@ -512,3 +512,51 @@ test('"USA" and "UK" name their countries, and a trailing comma keeps the nearby
|
||||
assert.equal(Math.round(result.lat), 34, `got ${result.label}`);
|
||||
assert.equal(fetchImpl.urls.length, 1);
|
||||
});
|
||||
|
||||
test('a region match takes the place itself, not a place whose name starts with it', () => {
|
||||
const station = {
|
||||
geometry: { type: 'Point', coordinates: [4.86, 45.76] },
|
||||
properties: {
|
||||
osm_key: 'railway',
|
||||
name: 'Paris Gare de Lyon',
|
||||
city: 'Lyon',
|
||||
country: 'France',
|
||||
countrycode: 'FR',
|
||||
},
|
||||
};
|
||||
const paris = {
|
||||
geometry: { type: 'Point', coordinates: [2.35, 48.86] },
|
||||
properties: {
|
||||
osm_key: 'place',
|
||||
name: 'Paris',
|
||||
state: 'Île-de-France',
|
||||
country: 'France',
|
||||
countrycode: 'FR',
|
||||
},
|
||||
};
|
||||
assert.equal(selectQualifiedFeature([station, paris], 'Paris, France'), paris);
|
||||
assert.equal(selectQualifiedFeature([station], 'Paris, France'), null);
|
||||
});
|
||||
|
||||
test('"UK" names the United Kingdom', () => {
|
||||
const london = {
|
||||
geometry: { type: 'Point', coordinates: [-0.13, 51.51] },
|
||||
properties: {
|
||||
osm_key: 'place',
|
||||
name: 'London',
|
||||
country: 'United Kingdom',
|
||||
countrycode: 'GB',
|
||||
},
|
||||
};
|
||||
const ontario = {
|
||||
geometry: { type: 'Point', coordinates: [-81.25, 42.98] },
|
||||
properties: {
|
||||
osm_key: 'place',
|
||||
name: 'London',
|
||||
state: 'Ontario',
|
||||
country: 'Canada',
|
||||
countrycode: 'CA',
|
||||
},
|
||||
};
|
||||
assert.equal(selectQualifiedFeature([ontario, london], 'London, UK'), london);
|
||||
});
|
||||
Reference in new issue
Block a user