mirror of
https://iceshrimp.dev/limepotato/jormungandr-bite.git
synced 2024-11-28 21:08:52 -07:00
[backend] Improve postgres FTS tokenizer
This commit is contained in:
parent
e405d348ed
commit
c72eb36d66
1 changed files with 5 additions and 5 deletions
|
@ -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(')')) {
|
||||||
|
|
Loading…
Reference in a new issue