Fill the gaps Google leaves from the free sources

This commit is contained in:
Maurice
2026-08-10 11:33:08 +02:00
committed by Maurice
parent 0cd67675c5
commit ad6640cdb2
4 changed files with 120 additions and 7 deletions
+10 -2
View File
@@ -373,8 +373,16 @@ export function parseOpeningHours(ohString: string): {
.split('-')
.map((d) => DAYS.indexOf(d.trim()));
if (parts.length === 2 && parts[0] >= 0 && parts[1] >= 0) {
for (let i = parts[0]; i !== (parts[1] + 1) % 7; i = (i + 1) % 7) dayIndices.add(i);
dayIndices.add(parts[1]);
// do/while, not while: a range that wraps all the way round — "Mo-Su",
// or "Tu-Mo", both of which mean every day — starts already satisfying
// the exit condition, so the loop never ran and only the closing day
// was added. "Mo-Su 11:30-23:00" is how a place open daily is usually
// tagged, and it produced exactly one day of hours.
let day = parts[0];
do {
dayIndices.add(day);
day = (day + 1) % 7;
} while (day !== (parts[1] + 1) % 7);
} else if (parts[0] >= 0) {
dayIndices.add(parts[0]);
}
@@ -213,6 +213,19 @@ export function collectHours(details: Record<string, unknown> | null): PlaceHour
};
}
/**
* Facts from the maps provider, topped up from OpenStreetMap.
*
* Provider first where both know a thing: it is the source the user searched
* and the one more likely to be current for a business. OSM contributes
* everything the provider has no concept of, which for Google is most of this
* list — cuisine, wheelchair access, outdoor seating, the menu link.
*/
export function mergeFacts(primary: PlaceFact[], extra: PlaceFact[]): PlaceFact[] {
const seen = new Set(primary.map((fact) => fact.kind));
return [...primary, ...extra.filter((fact) => !seen.has(fact.kind))];
}
/** The provider's star rating, with its count when there is one. */
export function collectRating(details: Record<string, unknown> | null): PlaceRating | null {
const value = typeof details?.rating === 'number' ? details.rating : null;
@@ -281,12 +294,18 @@ export class PlaceEnrichmentService {
// no transport deadline at all.
const osmDetails = identity.osmTags ? buildOsmDetails(identity.osmTags, '', '') : null;
// Where Google is silent, the free sources fill in. Google's payload has no
// cuisine, no wheelchair access, no outdoor seating and no menu link — it
// never had — so a Google place used to show a rating and nothing else,
// while the same building in OpenStreetMap carried all of it. Each field is
// taken from whichever source actually has it rather than from one source
// for everything.
const result: CachedEnrichment = {
photos,
description,
facts: collectFacts(details),
facts: mergeFacts(collectFacts(details), collectFacts(osmDetails)),
hours: collectHours(details) ?? collectHours(osmDetails),
rating: collectRating(details),
rating: collectRating(details) ?? collectRating(osmDetails),
};
this.writeCache(placeId, lang, result);
return result;