@@ -95,11 +95,30 @@ 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
+ termRegex := regexp .MustCompile (`("[^"]+"|\S+)` )
102
+ matches := termRegex .FindAllString (query , - 1 )
103
+
104
+ for _ , match := range matches {
105
+ if match [0 ] == '"' && match [len (match )- 1 ] == '"' {
106
+ match = match [1 : len (match )- 1 ]
107
+ }
108
+
109
+ keywords = append (keywords , strings .ReplaceAll (match , "*" , "" ))
110
+ }
111
+
112
+ return keywords
113
+ }
114
+
98
115
func processLogsResponse (res * es.SearchResponse , target * Query , configuredFields es.ConfiguredFields , queryRes * backend.DataResponse ) error {
99
116
propNames := make (map [string ]bool )
100
117
docs := make ([]map [string ]interface {}, len (res .Hits .Hits ))
101
118
searchWords := make (map [string ]bool )
102
119
120
+ highlights := parseLuceneQuery (target .RawQuery )
121
+
103
122
for hitIdx , hit := range res .Hits .Hits {
104
123
var flattened map [string ]interface {}
105
124
if hit ["_source" ] != nil {
@@ -132,23 +151,6 @@ func processLogsResponse(res *es.SearchResponse, target *Query, configuredFields
132
151
propNames [key ] = true
133
152
}
134
153
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
154
docs [hitIdx ] = doc
153
155
}
154
156
@@ -158,6 +160,11 @@ func processLogsResponse(res *es.SearchResponse, target *Query, configuredFields
158
160
frames := data.Frames {}
159
161
frame := data .NewFrame ("" , fields ... )
160
162
setPreferredVisType (frame , data .VisTypeLogs )
163
+
164
+ for _ , keyword := range highlights {
165
+ searchWords [keyword ] = true
166
+ }
167
+
161
168
setLogsCustomMeta (frame , searchWords , stringToIntWithDefaultValue (target .Metrics [0 ].Settings .Get ("limit" ).MustString (), defaultSize ))
162
169
frames = append (frames , frame )
163
170
0 commit comments