Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit ecae1e8

Browse files
committed
Fixes u-bahn-app #237
1 parent 5e34f06 commit ecae1e8

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/common/es-helper.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ function getTotalCount (total) {
269269
}
270270

271271
function escapeRegex (str) {
272+
console.log('Escape', str)
272273
return str
273274
.replace(/[\*\+\-=~><\"\?^\${}\(\)\:\!\/[\]\\\s]/g, '\\$&') // replace single character special characters
274275
.replace(/\|\|/g, '\\||') // replace ||
@@ -630,7 +631,7 @@ function hasNonAlphaNumeric (text) {
630631
*/
631632
async function searchSkills (keyword) {
632633
const queryDoc = DOCUMENTS.skill
633-
634+
keyword = escapeRegex(keyword)
634635
const query = hasNonAlphaNumeric(keyword) ? `\\*${keyword}\\*` : `*${keyword}*`
635636

636637
const esQuery = {
@@ -655,14 +656,14 @@ async function searchSkills (keyword) {
655656

656657
async function setUserSearchClausesToEsQuery (boolClause, keyword) {
657658
const skillIds = await searchSkills(keyword)
658-
659659
boolClause.should.push({
660660
query_string: {
661661
fields: ['firstName', 'lastName', 'handle'],
662-
query: `*${keyword.replace(/ +/g, ' ').split(' ').join('* OR *')}*`
662+
query: `\\*${escapeRegex(keyword.replace(/ +/g, ' ')).split(' ').join('\\* OR \\*')}\\*`
663663
}
664664
})
665665

666+
keyword = escapeRegex(keyword)
666667
boolClause.should.push({
667668
nested: {
668669
path: USER_ATTRIBUTE.esDocumentPath,

0 commit comments

Comments
 (0)