From 391814a54e778aca0dfde7b8bd1de2a6357aaf65 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Fri, 2 Feb 2024 08:58:51 -0500 Subject: [PATCH] fix: Improve multi-partial word matching in search --- server/models/helpers/SearchHelper.ts | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/server/models/helpers/SearchHelper.ts b/server/models/helpers/SearchHelper.ts index 48293ca4c..ff43fe16e 100644 --- a/server/models/helpers/SearchHelper.ts +++ b/server/models/helpers/SearchHelper.ts @@ -416,12 +416,8 @@ export default class SearchHelper { // limit length of search queries as we're using regex against untrusted input let limitedQuery = this.escapeQuery(query.slice(0, this.maxQueryLength)); - // if the search term is one unquoted word then allow partial matches automatically - const queryWordCount = limitedQuery.split(" ").length; - const singleUnquotedSearch = - queryWordCount === 1 && - !limitedQuery.startsWith('"') && - !limitedQuery.endsWith('"'); + const quotedSearch = + limitedQuery.startsWith('"') && limitedQuery.endsWith('"'); // Replace single quote characters with &. const singleQuotes = limitedQuery.matchAll(/'+/g); @@ -440,7 +436,7 @@ export default class SearchHelper { } return ( - queryParser()(singleUnquotedSearch ? `${limitedQuery}*` : limitedQuery) + queryParser()(quotedSearch ? limitedQuery : `${limitedQuery}*`) // Remove any trailing join characters .replace(/&$/, "") );