@@ -62,28 +62,11 @@ const SUPPORTED_FILTERS = [
62
62
63
63
const escapeEsKeyword = keyword => keyword . replace ( / [ + - = > < ! | ( ) { } [ & \] ^ " ~ * ? : \\ / ] / g, '\\\\$&' ) ;
64
64
65
- /**
66
- * ES need to skip special chars else it is considered as RegEx
67
- *
68
- * @param {String } query query being searched for
69
- * @return {String } result after parsing
70
- */
71
- function escapeElasticsearchQuery ( query ) {
72
- const chars = [ '\\' , '+' , '-' , '&&' , '||' , '!' , '(' , ')' , '{' , '}' , '[' , ']' ,
73
- '^' , '"' , '~' , '*' , '?' , ':' , '/' , '<' , '>' ] ;
74
- let result = query ;
75
- _ . forEach ( chars , ( item ) => {
76
- result = result . replace ( item , `\\${ item } ` ) ;
77
- } ) ;
78
- return result ;
79
- }
80
-
81
65
const buildEsFullTextQuery = ( keyword , matchType , singleFieldName ) => {
82
- const escapedKeyword = escapeElasticsearchQuery ( keyword ) ;
83
66
let should = [
84
67
{
85
68
query_string : {
86
- query : ( matchType === MATCH_TYPE_EXACT_PHRASE ) ? escapedKeyword : `*${ escapedKeyword } *` ,
69
+ query : ( matchType === MATCH_TYPE_EXACT_PHRASE ) ? keyword : `*${ keyword } *` ,
87
70
analyze_wildcard : ( matchType === MATCH_TYPE_WILDCARD ) ,
88
71
fields : [ 'name^5' , 'description^3' , 'type^2' ] ,
89
72
} ,
@@ -96,7 +79,7 @@ const buildEsFullTextQuery = (keyword, matchType, singleFieldName) => {
96
79
path : 'details.utm' ,
97
80
query : {
98
81
query_string : {
99
- query : ( matchType === MATCH_TYPE_EXACT_PHRASE ) ? escapedKeyword : `*${ escapedKeyword } *` ,
82
+ query : ( matchType === MATCH_TYPE_EXACT_PHRASE ) ? keyword : `*${ keyword } *` ,
100
83
analyze_wildcard : ( matchType === MATCH_TYPE_WILDCARD || matchType === MATCH_TYPE_SINGLE_FIELD ) ,
101
84
fields : [ 'details.utm.code^4' ] ,
102
85
} ,
@@ -110,7 +93,7 @@ const buildEsFullTextQuery = (keyword, matchType, singleFieldName) => {
110
93
path : 'members' ,
111
94
query : {
112
95
query_string : {
113
- query : ( matchType === MATCH_TYPE_EXACT_PHRASE ) ? escapedKeyword : `*${ escapedKeyword } *` ,
96
+ query : ( matchType === MATCH_TYPE_EXACT_PHRASE ) ? keyword : `*${ keyword } *` ,
114
97
analyze_wildcard : ( matchType === MATCH_TYPE_WILDCARD ) ,
115
98
fields : [ 'members.email' , 'members.handle' , 'members.firstName' , 'members.lastName' ] ,
116
99
} ,
@@ -285,6 +268,22 @@ const setFilter = (value, keyword, fieldName) => {
285
268
return buildEsQueryWithFilter ( value , keyword , MATCH_TYPE_EXACT_PHRASE , fieldName ) ;
286
269
} ;
287
270
271
+ /**
272
+ * ES need to skip special chars else it is considered as RegEx
273
+ *
274
+ * @param {String } query query being searched for
275
+ * @return {String } result after parsing
276
+ */
277
+ function escapeElasticsearchQuery ( query ) {
278
+ const chars = [ '\\' , '+' , '-' , '&&' , '||' , '!' , '(' , ')' , '{' , '}' , '[' , ']' ,
279
+ '^' , '"' , '~' , '*' , '?' , ':' , '/' , '<' , '>' ] ;
280
+ let result = query ;
281
+ _ . forEach ( chars , ( item ) => {
282
+ result = result . replace ( item , `\\${ item } ` ) ;
283
+ } ) ;
284
+ return result ;
285
+ }
286
+
288
287
/**
289
288
* Parse the ES search criteria and prepare search request body
290
289
*
@@ -443,7 +442,7 @@ const parseElasticSearchCriteria = (criteria, fields, order) => {
443
442
444
443
if ( ! keyword ) {
445
444
// Not a specific field search nor an exact phrase search, do a wildcard match
446
- keyword = criteria . filters . keyword ;
445
+ keyword = escapeElasticsearchQuery ( keywordCriterion ) ;
447
446
matchType = MATCH_TYPE_WILDCARD ;
448
447
}
449
448
0 commit comments