This repository was archived by the owner on Mar 13, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +4
-3
lines changed Expand file tree Collapse file tree 1 file changed +4
-3
lines changed Original file line number Diff line number Diff line change @@ -269,6 +269,7 @@ function getTotalCount (total) {
269
269
}
270
270
271
271
function escapeRegex ( str ) {
272
+ console . log ( 'Escape' , str )
272
273
return str
273
274
. replace ( / [ \* \+ \- = ~ > < \" \? ^ \$ { } \( \) \: \! \/ [ \] \\ \s ] / g, '\\$&' ) // replace single character special characters
274
275
. replace ( / \| \| / g, '\\||' ) // replace ||
@@ -630,7 +631,7 @@ function hasNonAlphaNumeric (text) {
630
631
*/
631
632
async function searchSkills ( keyword ) {
632
633
const queryDoc = DOCUMENTS . skill
633
-
634
+ keyword = escapeRegex ( keyword )
634
635
const query = hasNonAlphaNumeric ( keyword ) ? `\\*${ keyword } \\*` : `*${ keyword } *`
635
636
636
637
const esQuery = {
@@ -655,14 +656,14 @@ async function searchSkills (keyword) {
655
656
656
657
async function setUserSearchClausesToEsQuery ( boolClause , keyword ) {
657
658
const skillIds = await searchSkills ( keyword )
658
-
659
659
boolClause . should . push ( {
660
660
query_string : {
661
661
fields : [ 'firstName' , 'lastName' , 'handle' ] ,
662
- query : `*${ keyword . replace ( / + / g, ' ' ) . split ( ' ' ) . join ( '* OR *' ) } *`
662
+ query : `\\ *${ escapeRegex ( keyword . replace ( / + / g, ' ' ) ) . split ( ' ' ) . join ( '\\ * OR \\ *' ) } \\ *`
663
663
}
664
664
} )
665
665
666
+ keyword = escapeRegex ( keyword )
666
667
boolClause . should . push ( {
667
668
nested : {
668
669
path : USER_ATTRIBUTE . esDocumentPath ,
You can’t perform that action at this time.
0 commit comments