From 8e9fc45928ae9bc664186d5f211ba5f447558528 Mon Sep 17 00:00:00 2001 From: "Patrik J. Braun" Date: Mon, 24 May 2021 00:07:19 +0200 Subject: [PATCH] fixing issue when searching for directory with brackets in its name #309 Example issue "2000.01.01 (An event)" --- src/common/SearchQueryParser.ts | 4 +++- test/common/unit/SearchQueryParser.ts | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/common/SearchQueryParser.ts b/src/common/SearchQueryParser.ts index 3760456b..d19a438b 100644 --- a/src/common/SearchQueryParser.ts +++ b/src/common/SearchQueryParser.ts @@ -87,7 +87,7 @@ export class SearchQueryParser { public parse(str: string, implicitAND = true): SearchQueryDTO { str = str.replace(/\s\s+/g, ' ') // remove double spaces - .replace(/:\s+/g, ':').replace(/\)(?=\S)/g, ') ').trim(); + .replace(/:\s+/g, ':').trim(); if (str.charAt(0) === '(' && str.charAt(str.length - 1) === ')') { str = str.slice(1, str.length - 1); @@ -253,9 +253,11 @@ export class SearchQueryParser { for (const typeTmp of tmp) { if (str.startsWith(typeTmp.key)) { const ret: TextSearch = Utils.clone(typeTmp.queryTemplate); + // exact match if (str.charAt(typeTmp.key.length) === '"' && str.charAt(str.length - 1) === '"') { ret.text = str.slice(typeTmp.key.length + 1, str.length - 1); ret.matchType = TextSearchQueryMatchTypes.exact_match; + // like match } else if (str.charAt(typeTmp.key.length) === '(' && str.charAt(str.length - 1) === ')') { ret.text = str.slice(typeTmp.key.length + 1, str.length - 1); } else { diff --git a/test/common/unit/SearchQueryParser.ts b/test/common/unit/SearchQueryParser.ts index 59a689eb..442ac117 100644 --- a/test/common/unit/SearchQueryParser.ts +++ b/test/common/unit/SearchQueryParser.ts @@ -58,6 +58,13 @@ describe('SearchQueryParser', () => { check({type: SearchQueryTypes.any_text, text: 'test'} as TextSearch); check({type: SearchQueryTypes.person, text: 'person_test'} as TextSearch); check({type: SearchQueryTypes.directory, text: 'directory'} as TextSearch); + check({type: SearchQueryTypes.directory, text: '2000.10.15 (Some event)'} as TextSearch); + check({ + type: SearchQueryTypes.directory, + text: '2000.10.15 (Some event)', + matchType: TextSearchQueryMatchTypes.exact_match + } as TextSearch); + check({type: SearchQueryTypes.directory, text: '2000.10.15 (Some event) '} as TextSearch); check({type: SearchQueryTypes.keyword, text: 'big boom'} as TextSearch); check({type: SearchQueryTypes.caption, text: 'caption'} as TextSearch); check({type: SearchQueryTypes.file_name, text: 'filename'} as TextSearch);