fixes and refactor
This commit is contained in:
@@ -2,13 +2,23 @@
|
||||
function buildTokens(rawQuery) {
|
||||
const q = (rawQuery || '').trim();
|
||||
if (!q) return [];
|
||||
// Normalize punctuation to spaces, trim non-alphanumerics at ends, dedupe
|
||||
// Normalize punctuation to spaces, trim non-alphanumerics at ends
|
||||
const tokens = q
|
||||
.replace(/[,_;:]+/g, ' ')
|
||||
.split(/\s+/)
|
||||
.map(t => t.replace(/^[^A-Za-z0-9]+|[^A-Za-z0-9]+$/g, ''))
|
||||
.filter(Boolean);
|
||||
return Array.from(new Set(tokens));
|
||||
// Case-insensitive dedupe while preserving original order and casing (parity with server)
|
||||
const seen = new Set();
|
||||
const result = [];
|
||||
for (const tok of tokens) {
|
||||
const lowered = tok.toLowerCase();
|
||||
if (!seen.has(lowered)) {
|
||||
seen.add(lowered);
|
||||
result.push(tok);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function escapeHtml(text) {
|
||||
|
||||
Reference in New Issue
Block a user