Erweiterte Werte übernehmen

This commit is contained in:
2026-07-17 12:44:13 +02:00
parent 5b20729877
commit 5989046b53
4 changed files with 39 additions and 13 deletions
+14 -2
View File
@@ -81,8 +81,16 @@ function searchCustomers(query, extraFields, limit) {
}
const haystack = haystackParts.join(" ").toLocaleLowerCase("de-DE");
if (!words.every((word) => haystack.includes(word))) continue;
// Werte aller ausgewählten erweiterten Felder, unabhängig davon, welches Wort den Treffer ausgelöst hat
const extraMatches = extraFields
.map((field) => customer[field])
.filter((value) => value !== undefined && value !== null && String(value).trim() !== "")
.map((value) => String(value));
const match = { number: customer.number, name: customer.name, extraMatches };
const isStartMatch = words.every((word) => haystack.startsWith(word) || haystack.includes(` ${word}`));
if (isStartMatch) { startMatches.push(customer); } else { partialMatches.push(customer); }
if (isStartMatch) { startMatches.push(match); } else { partialMatches.push(match); }
if (startMatches.length >= limit) break;
}
@@ -136,7 +144,11 @@ app.get("/api/customers", (request, response) => {
.map((field) => field.trim())
.filter((field) => ADVANCED_SEARCH_FIELDS.includes(field));
const matches = searchCustomers(query, extraFields, 12);
const results = matches.map((customer) => ({ number: customer.number, name: customer.name }));
const results = matches.map((customer) => ({
number: customer.number,
name: customer.name,
extraMatches: customer.extraMatches,
}));
return response.json({ results, total: customers.length });
});