From be2a724c0c8149c030a43b876c0b0648ac38f346 Mon Sep 17 00:00:00 2001 From: Simon Cambier Date: Sun, 18 Jun 2023 10:05:26 +0200 Subject: [PATCH] Improving quotes to allow `"hyphenated-words"` --- src/search/query.ts | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/search/query.ts b/src/search/query.ts index 848b2d9..065df00 100644 --- a/src/search/query.ts +++ b/src/search/query.ts @@ -9,11 +9,10 @@ type Keywords = { } & { text: string[] } export class Query { - query: Keywords & { exclude: Keywords } - /** - * @deprecated - */ - extensions: string[] = [] + query: Keywords & { + exclude: Keywords + } + #inQuotes: string[] constructor(text = '') { if (settings.ignoreDiacritics) { @@ -44,7 +43,10 @@ export class Query { } } this.query = parsed - this.extensions = this.query.ext ?? [] + + // Get strings in quotes, and remove the quotes + this.#inQuotes = + text.match(/"([^"]+)"/g)?.map(o => o.replace(/"/g, '')) ?? [] } public isEmpty(): boolean { @@ -62,7 +64,7 @@ export class Query { public segmentsToStr(): string { return this.query.text.join(' ') } - + public getTags(): string[] { return this.query.text.filter(o => o.startsWith('#')) } @@ -72,6 +74,11 @@ export class Query { } public getExactTerms(): string[] { - return this.query.text.filter(o => o.split(' ').length > 1) + return [ + ...new Set([ + ...this.query.text.filter(o => o.split(' ').length > 1), + ...this.#inQuotes, + ]), + ] } }