@@ -95,18 +95,46 @@ func parseResponse(responses []*es.SearchResponse, targets []*Query, configuredF
95
95
return & result , nil
96
96
}
97
97
98
+ func isLuceneOperator (value string ) bool {
99
+ operators := []string {"or" , "and" }
100
+ for _ , op := range operators {
101
+ if strings .ToLower (value ) == op {
102
+ return true
103
+ }
104
+ }
105
+
106
+ return false
107
+ }
108
+
98
109
func parseLuceneQuery (query string ) []string {
99
110
var keywords []string
100
111
101
112
termRegex := regexp .MustCompile (`("[^"]+"|\S+)` )
102
- matches := termRegex .FindAllString (query , - 1 )
113
+ keyValueRegex := regexp .MustCompile (`[^:]+:([^:]*)` )
114
+ termMatches := termRegex .FindAllString (query , - 1 )
103
115
104
- for _ , match := range matches {
105
- if match [0 ] == '"' && match [len (match )- 1 ] == '"' {
106
- match = match [1 : len (match )- 1 ]
116
+ for _ , termMatch := range termMatches {
117
+ if termMatch [0 ] == '"' && termMatch [len (termMatches )- 1 ] == '"' {
118
+ termMatch = termMatch [1 : len (termMatch )- 1 ]
107
119
}
108
120
109
- keywords = append (keywords , strings .ReplaceAll (match , "*" , "" ))
121
+ keyValueMatches := keyValueRegex .FindStringSubmatch (termMatch )
122
+ if len (keyValueMatches ) <= 1 {
123
+ value := strings .ReplaceAll (termMatch , "*" , "" )
124
+ if isLuceneOperator (value ) {
125
+ continue
126
+ }
127
+ keywords = append (keywords , value )
128
+ continue
129
+ }
130
+
131
+ for _ , keyValueMatch := range keyValueMatches [1 :] {
132
+ value := strings .ReplaceAll (keyValueMatch , "*" , "" )
133
+ if isLuceneOperator (value ) {
134
+ continue
135
+ }
136
+ keywords = append (keywords , value )
137
+ }
110
138
}
111
139
112
140
return keywords
0 commit comments