From c5b657a96adc314442006880cd15b4308040be95 Mon Sep 17 00:00:00 2001 From: "Patrik J. Braun" Date: Sat, 20 Mar 2021 23:31:39 +0100 Subject: [PATCH] Fixing search query parser --- src/common/SearchQueryParser.ts | 16 ++++++++-------- .../search/search-query-parser.service.ts | 2 +- test/common/unit/SearchQueryParser.ts | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/common/SearchQueryParser.ts b/src/common/SearchQueryParser.ts index 18b34c3a..20482dfc 100644 --- a/src/common/SearchQueryParser.ts +++ b/src/common/SearchQueryParser.ts @@ -106,10 +106,10 @@ export class SearchQueryParser { } } if (str.startsWith(this.keywords.someOf + ':') || - new RegExp(/^\d*-of:/).test(str)) { + new RegExp('^\\d*-' + this.keywords.NSomeOf + ':').test(str)) { const prefix = str.startsWith(this.keywords.someOf + ':') ? this.keywords.someOf + ':' : - new RegExp(/^\d*-of:/).exec(str)[0]; + new RegExp('^\\d*-' + this.keywords.NSomeOf + ':').exec(str)[0]; let tmpList: any = this.parse(str.slice(prefix.length + 1, -1), false); // trim brackets // console.log(JSON.stringify(tmpList, null, 4)); const unfoldList = (q: SearchListQuery): SearchQueryDTO[] => { @@ -127,7 +127,7 @@ export class SearchQueryParser { type: SearchQueryTypes.SOME_OF, list: tmpList }; - if (new RegExp('/^\d*-' + this.keywords.NSomeOf + ':/').test(str)) { + if (new RegExp('^\\d*-' + this.keywords.NSomeOf + ':').test(str)) { ret.min = parseInt(new RegExp(/^\d*/).exec(str)[0], 10); } return ret; @@ -170,8 +170,8 @@ export class SearchQueryParser { value: parseInt(str.slice((this.keywords.maxResolution + ':').length), 10) }; } - if (new RegExp('/^\d*-' + this.keywords.kmFrom + ':/').test(str)) { - let from = str.slice(new RegExp('/^\d*-' + this.keywords.kmFrom + ':/').exec(str)[0].length); + if (new RegExp('^\\d*-' + this.keywords.kmFrom + ':').test(str)) { + let from = str.slice(new RegExp('^\\d*-' + this.keywords.kmFrom + ':').exec(str)[0].length); if (from.charAt(0) === '(' && from.charAt(from.length - 1) === ')') { from = from.slice(1, from.length - 1); } @@ -279,12 +279,12 @@ export class SearchQueryParser { return ''; } if ((query).matchType === TextSearchQueryMatchTypes.exact_match) { - return SearchQueryTypes[query.type] + ':"' + (query).text + '"'; + return (this.keywords)[SearchQueryTypes[query.type]] + ':"' + (query).text + '"'; } else if ((query).text.indexOf(' ') !== -1) { - return SearchQueryTypes[query.type] + ':(' + (query).text + ')'; + return (this.keywords)[SearchQueryTypes[query.type]] + ':(' + (query).text + ')'; } - return SearchQueryTypes[query.type] + ':' + (query).text; + return (this.keywords)[SearchQueryTypes[query.type]] + ':' + (query).text; default: throw new Error('Unknown type: ' + query.type); diff --git a/src/frontend/app/ui/gallery/search/search-query-parser.service.ts b/src/frontend/app/ui/gallery/search/search-query-parser.service.ts index 4bfdcd99..9b8c9267 100644 --- a/src/frontend/app/ui/gallery/search/search-query-parser.service.ts +++ b/src/frontend/app/ui/gallery/search/search-query-parser.service.ts @@ -6,7 +6,7 @@ import {SearchQueryDTO} from '../../../../../common/entities/SearchQueryDTO'; export class SearchQueryParserService { public readonly keywords: QueryKeywords = { - NSomeOf: '-of', + NSomeOf: 'of', and: 'and', caption: 'caption', directory: 'directory', diff --git a/test/common/unit/SearchQueryParser.ts b/test/common/unit/SearchQueryParser.ts index d2de5a36..442a1ca7 100644 --- a/test/common/unit/SearchQueryParser.ts +++ b/test/common/unit/SearchQueryParser.ts @@ -18,7 +18,7 @@ import { } from '../../../src/common/entities/SearchQueryDTO'; import {QueryKeywords, SearchQueryParser} from '../../../src/common/SearchQueryParser'; -describe('SearchQueryDTO', () => { +describe('SearchQueryParser', () => { const keywords: QueryKeywords = { NSomeOf: '-of',