1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2025-01-14 14:43:17 +08:00

fixing issue when searching for directory with brackets in its name #309

Example issue "2000.01.01 (An event)"
This commit is contained in:
Patrik J. Braun 2021-05-24 00:07:19 +02:00
parent 688f3b6dec
commit 8e9fc45928
2 changed files with 10 additions and 1 deletions

View File

@ -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 {

View File

@ -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);