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) {
269269}
270270
271271function 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 */
631632async 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
656657async 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 ,
You can’t perform that action at this time.
0 commit comments