完善搜索点位分类与稳定定位
Some checks failed
CI / verify (push) Has been cancelled

This commit is contained in:
lyf
2026-07-12 04:10:34 +08:00
parent d8420fc7c2
commit f94af2de4d
5 changed files with 188 additions and 37 deletions

View File

@@ -86,13 +86,17 @@ const toGuideRenderPoi = (poi: MuseumPoi): GuideRenderPoi => ({
const toSgsRenderPoi = (poi: ReturnType<typeof toMuseumPoiFromSgs>) => toGuideRenderPoi(poi)
const getRenderPoiDedupeKeys = (poi: GuideRenderPoi) => [
poi.id ? `id:${poi.id}` : '',
poi.sourceSpaceId ? `space:${poi.floorId}:${poi.sourceSpaceId}` : '',
poi.spaceId ? `space:${poi.floorId}:${poi.spaceId}` : '',
poi.sourcePlaceId ? `place:${poi.floorId}:${poi.sourcePlaceId}` : '',
poi.sourceObjectName ? `object:${poi.floorId}:${poi.sourceObjectName}` : ''
].filter(Boolean)
const getRenderPoiDedupeKeys = (poi: GuideRenderPoi) => {
const stableKeys = [
poi.id ? `id:${poi.id}` : '',
poi.sourceSpaceId ? `space:${poi.floorId}:${poi.sourceSpaceId}` : '',
poi.spaceId ? `space:${poi.floorId}:${poi.spaceId}` : '',
poi.sourcePlaceId ? `place:${poi.floorId}:${poi.sourcePlaceId}` : ''
].filter(Boolean)
if (stableKeys.length) return stableKeys
return poi.sourceObjectName ? [`object:${poi.floorId}:${poi.sourceObjectName}`] : []
}
const dedupeRenderPoisById = (pois: GuideRenderPoi[]) => {
const seen = new Set<string>()
@@ -523,7 +527,7 @@ export class SgsSdkGuideModelRepository implements GuideModelRepository {
fallbackHallY: floorPoiMedianY ?? null
})
if (hallDiagnostics.hallPoiWithPositionCount > 0 && !renderPois.some((poi) => poi.primaryCategory === 'exhibition_hall')) {
if (hallDiagnostics.hallPoiWithPositionCount > 0 && !renderHallPois.length) {
warnSgsGuideModelDiagnostics('render POI filter removed all hall POIs', {
floorId: resolvedFloorId,
...hallDiagnostics,

View File

@@ -4,6 +4,7 @@ import type {
GuideLocationPreview,
GuideMapDiagnostics,
GuideRouteReadiness,
MuseumCategory,
MuseumFloor,
MuseumPoi
} from '@/domain/museum'
@@ -132,9 +133,28 @@ const dedupePoisById = (pois: MuseumPoi[]) => {
const getPoiSpaceIdentity = (poi: MuseumPoi) => poi.sourceSpaceId || poi.spaceId || ''
const getPoiLookupIdentities = (id: string) => {
const normalizedId = id.trim()
return new Set([
normalizedId,
normalizedId.replace(/^(?:hall|space)-/, '')
].filter(Boolean))
}
const mergePoiCategories = (...categoryGroups: MuseumCategory[][]) => {
const seenIds = new Set<string>()
return categoryGroups.flat().filter((category) => {
const categoryId = category.id.trim()
if (!categoryId || seenIds.has(categoryId)) return false
seenIds.add(categoryId)
return true
})
}
const mergeSearchablePois = (pois: MuseumPoi[], spacePoints: MuseumPoi[]) => {
const hallPoisBySpaceId = new Map(
pois
.filter((poi) => poi.kind === 'hall' || Boolean(poi.hallId))
.map((poi) => [getPoiSpaceIdentity(poi), poi] as const)
.filter(([spaceId]) => Boolean(spaceId))
)
@@ -144,24 +164,30 @@ const mergeSearchablePois = (pois: MuseumPoi[], spacePoints: MuseumPoi[]) => {
.filter(([spaceId]) => Boolean(spaceId))
)
const filteredPois = pois.filter((poi) => {
const mergedPois = pois.map((poi) => {
const spaceId = getPoiSpaceIdentity(poi)
const matchingSpacePoint = spaceId ? spacePointsBySpaceId.get(spaceId) : null
if (!matchingSpacePoint) return true
const matchingHallPoi = spaceId ? hallPoisBySpaceId.get(spaceId) : null
if (!matchingSpacePoint || matchingHallPoi?.id !== poi.id) return poi
return matchingSpacePoint.primaryCategory.id === 'exhibition_hall'
return {
...poi,
primaryCategory: matchingSpacePoint.primaryCategory,
categories: mergePoiCategories(
[matchingSpacePoint.primaryCategory],
matchingSpacePoint.categories
)
}
})
const filteredSpacePoints = spacePoints.filter((poi) => {
const unmatchedSpacePoints = spacePoints.filter((poi) => {
const spaceId = getPoiSpaceIdentity(poi)
const matchingHallPoi = spaceId ? hallPoisBySpaceId.get(spaceId) : null
if (!matchingHallPoi) return true
return poi.primaryCategory.id !== 'exhibition_hall'
return !matchingHallPoi
})
return dedupePoisById([
...filteredPois,
...filteredSpacePoints
...mergedPois,
...unmatchedSpacePoints
])
}
@@ -527,7 +553,12 @@ export class SgsSdkGuideRepository implements GuideRepository {
async getPoiById(id: string) {
const pois = await this.searchPois()
return pois.find((poi) => poi.id === id || poi.spaceId === id || poi.sourceSpaceId === id)
const lookupIdentities = getPoiLookupIdentities(id)
return pois.find((poi) => (
lookupIdentities.has(poi.id)
|| lookupIdentities.has(poi.spaceId || '')
|| lookupIdentities.has(poi.sourceSpaceId || '')
))
|| findPoiByNavIdNameFallback(pois, id)
}