From 635d694d0dde990f52c2e871f5e490cc6e3daefa Mon Sep 17 00:00:00 2001 From: Michal Klobukowski Date: Wed, 13 Mar 2019 12:05:38 +0100 Subject: [PATCH] Remove duplicates from result of findSearchString Feature #14917 Arvados-DCO-1.1-Signed-off-by: Michal Klobukowski --- src/store/search-bar/search-query/parser.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/store/search-bar/search-query/parser.ts b/src/store/search-bar/search-query/parser.ts index 5fb82e4d0f..6eb01b85e4 100644 --- a/src/store/search-bar/search-query/parser.ts +++ b/src/store/search-bar/search-query/parser.ts @@ -2,6 +2,8 @@ // // SPDX-License-Identifier: AGPL-3.0 +import { uniq } from 'lodash/fp'; + export interface ParsedSearchQuery { tokens: string[]; searchString: string; @@ -25,7 +27,12 @@ export const findAllTokens = (query: string, patterns: RegExp[]): string[] => { }; export const findSearchString = (query: string, tokens: string[]) => { - return tokens.reduce((q, token) => q.replace(token, ''), query); + const uniqueWords = uniq(tokens + .reduce((q, token) => q.replace(token, ''), query) + .split(' ') + .filter(word => word !== '') + ); + return uniqueWords.join(' '); }; export const parseSearchQuery = (patterns: RegExp[]) => (query: string): ParsedSearchQuery => { -- 2.30.2