[backend] Improve postgres FTS tokenizer

This commit is contained in:
Laura Hausmann 2023-11-18 03:40:18 +01:00
parent e405d348ed
commit c72eb36d66
No known key found for this signature in database
GPG key ID: D044E84C5BE01605

View file

@ -45,18 +45,18 @@ export function generateFtsQuery(query: SelectQueryBuilder<any>, q: string): voi
let state: 'idle' | 'quote' | 'parenthesis' = 'idle'; let state: 'idle' | 'quote' | 'parenthesis' = 'idle';
for (let i = 0; i < terms.length; i++) { for (let i = 0; i < terms.length; i++) {
if (state === 'idle') { if (state === 'idle') {
if (terms[i].startsWith('"')) { if ((terms[i].startsWith('"') && terms[i].endsWith('"')) || (terms[i].startsWith('(') && terms[i].endsWith(')'))) {
finalTerms.push(trimStartAndEnd(terms[i]));
} else if (terms[i].startsWith('"')) {
idx = i; idx = i;
state = 'quote'; state = 'quote';
} else if (terms[i].startsWith('(')) { } else if (terms[i].startsWith('(')) {
idx = i; idx = i;
state = 'parenthesis'; state = 'parenthesis';
} } else {
else {
finalTerms.push(terms[i]); finalTerms.push(terms[i]);
} }
} } else if (state === 'quote' && terms[i].endsWith('"')) {
else if (state === 'quote' && terms[i].endsWith('"')) {
finalTerms.push(extractToken(terms, idx, i)); finalTerms.push(extractToken(terms, idx, i));
state = 'idle'; state = 'idle';
} else if (state === 'parenthesis' && terms[i].endsWith(')')) { } else if (state === 'parenthesis' && terms[i].endsWith(')')) {