mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-13 14:55:16 +00:00
Nova Soure vs Nova Canaã compartilham o primeiro token; distinctWordStartQuery escolhe palavra que casa só com o alvo e evita falso positivo no assessor.
27 lines
1.2 KiB
TypeScript
27 lines
1.2 KiB
TypeScript
import { homeSearchQueryIsActive } from '@/lib/campaignHomeSearchContract'
|
|
import { normalizeHomeSearchName } from '@/lib/homeSearchMunicipalityMatch'
|
|
import { matchesNormalizedAtWordStart } from '@/lib/wordStartFilter'
|
|
|
|
/**
|
|
* Picks a word-start query that matches `targetName` but not `excludeName`.
|
|
* Portfolio scoping specs allocate two municipalities per test; sharing the
|
|
* first token (e.g. Nova Soure vs Nova Canaã) makes advisor assertions flaky.
|
|
*/
|
|
export function distinctWordStartQuery(targetName: string, excludeName: string): string {
|
|
const normalizedTarget = normalizeHomeSearchName(targetName)
|
|
const normalizedExclude = normalizeHomeSearchName(excludeName)
|
|
|
|
for (const word of targetName.split(/\s+/)) {
|
|
const query = word.trim()
|
|
if (!homeSearchQueryIsActive(normalizeHomeSearchName(query))) continue
|
|
const normalizedQuery = normalizeHomeSearchName(query)
|
|
if (
|
|
matchesNormalizedAtWordStart(normalizedTarget, normalizedQuery) &&
|
|
!matchesNormalizedAtWordStart(normalizedExclude, normalizedQuery)
|
|
) {
|
|
return query
|
|
}
|
|
}
|
|
|
|
throw new Error(`No word-start query matches "${targetName}" without matching "${excludeName}"`)
|
|
}
|