@@ -95,11 +95,32 @@ func parseResponse(responses []*es.SearchResponse, targets []*Query, configuredF
95
95
return & result , nil
96
96
}
97
97
98
+ func parseLuceneQuery (query string ) []string {
99
+ var keywords []string
100
+
101
+ // Extract terms and phrases
102
+ termRegex := regexp .MustCompile (`("[^"]+"|\S+)` )
103
+ matches := termRegex .FindAllString (query , - 1 )
104
+
105
+ for _ , match := range matches {
106
+ // Remove quotes from phrases
107
+ if match [0 ] == '"' && match [len (match )- 1 ] == '"' {
108
+ keywords = append (keywords , match [1 :len (match )- 1 ])
109
+ } else {
110
+ keywords = append (keywords , match )
111
+ }
112
+ }
113
+
114
+ return keywords
115
+ }
116
+
98
117
func processLogsResponse (res * es.SearchResponse , target * Query , configuredFields es.ConfiguredFields , queryRes * backend.DataResponse ) error {
99
118
propNames := make (map [string ]bool )
100
119
docs := make ([]map [string ]interface {}, len (res .Hits .Hits ))
101
120
searchWords := make (map [string ]bool )
102
121
122
+ highlights := parseLuceneQuery (target .RawQuery )
123
+
103
124
for hitIdx , hit := range res .Hits .Hits {
104
125
var flattened map [string ]interface {}
105
126
if hit ["_source" ] != nil {
@@ -132,23 +153,6 @@ func processLogsResponse(res *es.SearchResponse, target *Query, configuredFields
132
153
propNames [key ] = true
133
154
}
134
155
135
- // FIXME: Quickwit does not support highlight. Should we replace this by a custom highlighter?
136
- // Process highlight to searchWords
137
- if highlights , ok := doc ["highlight" ].(map [string ]interface {}); ok {
138
- for _ , highlight := range highlights {
139
- if highlightList , ok := highlight .([]interface {}); ok {
140
- for _ , highlightValue := range highlightList {
141
- str := fmt .Sprintf ("%v" , highlightValue )
142
- matches := searchWordsRegex .FindAllStringSubmatch (str , - 1 )
143
-
144
- for _ , v := range matches {
145
- searchWords [v [1 ]] = true
146
- }
147
- }
148
- }
149
- }
150
- }
151
-
152
156
docs [hitIdx ] = doc
153
157
}
154
158
@@ -158,6 +162,11 @@ func processLogsResponse(res *es.SearchResponse, target *Query, configuredFields
158
162
frames := data.Frames {}
159
163
frame := data .NewFrame ("" , fields ... )
160
164
setPreferredVisType (frame , data .VisTypeLogs )
165
+
166
+ for _ , keyword := range highlights {
167
+ searchWords [keyword ] = true
168
+ }
169
+
161
170
setLogsCustomMeta (frame , searchWords , stringToIntWithDefaultValue (target .Metrics [0 ].Settings .Get ("limit" ).MustString (), defaultSize ))
162
171
frames = append (frames , frame )
163
172
0 commit comments