From ecae1e8f8f9483b4dceb53132d2589a516dccca9 Mon Sep 17 00:00:00 2001 From: Rakib Ansary Saikot Date: Tue, 28 Jul 2020 22:51:32 +0600 Subject: [PATCH 1/2] Fixes u-bahn-app #237 --- src/common/es-helper.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/common/es-helper.js b/src/common/es-helper.js index d5f4e90..977a649 100644 --- a/src/common/es-helper.js +++ b/src/common/es-helper.js @@ -269,6 +269,7 @@ function getTotalCount (total) { } function escapeRegex (str) { + console.log('Escape', str) return str .replace(/[\*\+\-=~><\"\?^\${}\(\)\:\!\/[\]\\\s]/g, '\\$&') // replace single character special characters .replace(/\|\|/g, '\\||') // replace || @@ -630,7 +631,7 @@ function hasNonAlphaNumeric (text) { */ async function searchSkills (keyword) { const queryDoc = DOCUMENTS.skill - + keyword = escapeRegex(keyword) const query = hasNonAlphaNumeric(keyword) ? `\\*${keyword}\\*` : `*${keyword}*` const esQuery = { @@ -655,14 +656,14 @@ async function searchSkills (keyword) { async function setUserSearchClausesToEsQuery (boolClause, keyword) { const skillIds = await searchSkills(keyword) - boolClause.should.push({ query_string: { fields: ['firstName', 'lastName', 'handle'], - query: `*${keyword.replace(/ +/g, ' ').split(' ').join('* OR *')}*` + query: `\\*${escapeRegex(keyword.replace(/ +/g, ' ')).split(' ').join('\\* OR \\*')}\\*` } }) + keyword = escapeRegex(keyword) boolClause.should.push({ nested: { path: USER_ATTRIBUTE.esDocumentPath, From 4b602b94b5f364d83b42f3696fe1ded04b55947b Mon Sep 17 00:00:00 2001 From: Rakib Ansary Saikot Date: Tue, 28 Jul 2020 22:52:38 +0600 Subject: [PATCH 2/2] Fixes u-bahn-app #237 --- src/common/es-helper.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/common/es-helper.js b/src/common/es-helper.js index 977a649..b582557 100644 --- a/src/common/es-helper.js +++ b/src/common/es-helper.js @@ -269,7 +269,6 @@ function getTotalCount (total) { } function escapeRegex (str) { - console.log('Escape', str) return str .replace(/[\*\+\-=~><\"\?^\${}\(\)\:\!\/[\]\\\s]/g, '\\$&') // replace single character special characters .replace(/\|\|/g, '\\||') // replace ||