normalization optimized
This commit is contained in:
@@ -47,9 +47,9 @@
|
||||
}
|
||||
|
||||
function normalize(value) {
|
||||
const sharedNormalize = window.AssetManagerNormalizeSearchText;
|
||||
if (typeof sharedNormalize === 'function') {
|
||||
return sharedNormalize(value, {
|
||||
const sharedKey = window.AssetManagerGermanSearchKey;
|
||||
if (typeof sharedKey === 'function') {
|
||||
return sharedKey(value, {
|
||||
caseSensitive: !caseInsensitive.checked,
|
||||
collapseWhitespace: true
|
||||
});
|
||||
|
||||
@@ -11,11 +11,11 @@
|
||||
const table = document.getElementById('software-inventory-table');
|
||||
if (filter && table) {
|
||||
filter.addEventListener('input', () => {
|
||||
const normalize = window.AssetManagerNormalizeSearchText ||
|
||||
((value) => String(value || '').toLocaleLowerCase());
|
||||
const needle = normalize(filter.value.trim());
|
||||
const matches = window.AssetManagerSearchTextMatches ||
|
||||
((value, term) => String(value || '').toLocaleLowerCase().includes(String(term || '').toLocaleLowerCase()));
|
||||
const needle = filter.value.trim();
|
||||
table.querySelectorAll('tbody tr').forEach((row) => {
|
||||
row.hidden = Boolean(needle) && !normalize(row.textContent).includes(needle);
|
||||
row.hidden = Boolean(needle) && !matches(row.textContent, needle);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user