normalization optimized

This commit is contained in:
2026-08-03 21:51:54 +00:00
parent bfc6128353
commit bd23858537
8 changed files with 95 additions and 46 deletions
+41 -17
View File
@@ -4,28 +4,52 @@
const collapseWhitespace = Boolean(options.collapseWhitespace);
let text = String(value ?? '');
// Preserve the common German transliterations before Unicode accent
// folding so searches treat umlauts and their ASCII spellings equally.
text = text
.replace(/Ä/g, 'Ae')
.replace(/Ö/g, 'Oe')
.replace(/Ü/g, 'Ue')
.replace(/ä/g, 'ae')
.replace(/ö/g, 'oe')
.replace(/ü/g, 'ue')
.replace(/ẞ/g, 'SS')
.replace(/ß/g, 'ss')
.normalize('NFKD')
.replace(/[\u0300-\u036f]/g, '');
if (collapseWhitespace) text = text.trim().replace(/\s+/g, ' ');
if (!caseSensitive) text = text.toLocaleLowerCase();
return text;
const protectedGerman = text
.replace(/ä/g, '\uE000')
.replace(/ö/g, '\uE001')
.replace(/ü/g, '\uE002')
.replace(/ß/g, '\uE003');
return protectedGerman
.normalize('NFKD')
.replace(/[\u0300-\u036f]/g, '')
.replace(/\uE000/g, 'ä')
.replace(/\uE001/g, 'ö')
.replace(/\uE002/g, 'ü')
.replace(/\uE003/g, 'ß');
}
function germanSearchKey(value, options = {}) {
let text = normalizeSearchText(value, options);
// Mark only plausible ASCII umlaut spellings. The marker keeps a real or
// transliterated umlaut distinct from natural letter pairs in words such
// as "Bauer", "teuer" and "euer".
text = text.replace(/(^|[^aeiouäöü])([aou])e/g, '$1$2~e');
return text
.replace(/ä/g, 'a~e')
.replace(/ö/g, 'o~e')
.replace(/ü/g, 'u~e')
.replace(/ß/g, 's~s');
}
function searchTextMatches(value, term, options = {}) {
const directValue = normalizeSearchText(value, options);
const directTerm = normalizeSearchText(term, options);
if (!directTerm) return true;
if (directValue.includes(directTerm)) return true;
return germanSearchKey(value, options).includes(germanSearchKey(term, options));
}
// Standalone filters and duplicate detection use the exact same comparison
// rules as the generic table filters.
window.AssetManagerNormalizeSearchText = normalizeSearchText;
window.AssetManagerGermanSearchKey = germanSearchKey;
window.AssetManagerSearchTextMatches = searchTextMatches;
const collator = new Intl.Collator(document.documentElement.lang || 'de', {
numeric: true,
@@ -387,7 +411,7 @@
const active = filterDefinitions
.map(definition => ({
definition,
term: normalizeSearchText(definition.input?.value.trim() || '')
term: definition.input?.value.trim() || ''
}))
.filter(item => item.term);
@@ -415,7 +439,7 @@
if (definition.numericFilter) {
return !numericFilterMatches(value, term);
}
return !normalizeSearchText(value).includes(term);
return !searchTextMatches(value, term);
});
row.hidden = hidden;