From c72eb36d6604542fc2d240ae803072f5bf670103 Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Sat, 18 Nov 2023 03:40:18 +0100 Subject: [PATCH] [backend] Improve postgres FTS tokenizer --- .../src/server/api/common/generate-fts-query.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/backend/src/server/api/common/generate-fts-query.ts b/packages/backend/src/server/api/common/generate-fts-query.ts index 830fb3e9d..3817f4050 100644 --- a/packages/backend/src/server/api/common/generate-fts-query.ts +++ b/packages/backend/src/server/api/common/generate-fts-query.ts @@ -45,18 +45,18 @@ export function generateFtsQuery(query: SelectQueryBuilder, q: string): voi let state: 'idle' | 'quote' | 'parenthesis' = 'idle'; for (let i = 0; i < terms.length; i++) { 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; state = 'quote'; } else if (terms[i].startsWith('(')) { idx = i; state = 'parenthesis'; - } - else { + } else { finalTerms.push(terms[i]); } - } - else if (state === 'quote' && terms[i].endsWith('"')) { + } else if (state === 'quote' && terms[i].endsWith('"')) { finalTerms.push(extractToken(terms, idx, i)); state = 'idle'; } else if (state === 'parenthesis' && terms[i].endsWith(')')) {