@@ -95,11 +95,32 @@ func parseResponse(responses []*es.SearchResponse, targets []*Query, configuredF
9595 return & result , nil
9696}
9797
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+
98117func processLogsResponse (res * es.SearchResponse , target * Query , configuredFields es.ConfiguredFields , queryRes * backend.DataResponse ) error {
99118 propNames := make (map [string ]bool )
100119 docs := make ([]map [string ]interface {}, len (res .Hits .Hits ))
101120 searchWords := make (map [string ]bool )
102121
122+ highlights := parseLuceneQuery (target .RawQuery )
123+
103124 for hitIdx , hit := range res .Hits .Hits {
104125 var flattened map [string ]interface {}
105126 if hit ["_source" ] != nil {
@@ -132,23 +153,6 @@ func processLogsResponse(res *es.SearchResponse, target *Query, configuredFields
132153 propNames [key ] = true
133154 }
134155
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-
152156 docs [hitIdx ] = doc
153157 }
154158
@@ -158,6 +162,11 @@ func processLogsResponse(res *es.SearchResponse, target *Query, configuredFields
158162 frames := data.Frames {}
159163 frame := data .NewFrame ("" , fields ... )
160164 setPreferredVisType (frame , data .VisTypeLogs )
165+
166+ for _ , keyword := range highlights {
167+ searchWords [keyword ] = true
168+ }
169+
161170 setLogsCustomMeta (frame , searchWords , stringToIntWithDefaultValue (target .Metrics [0 ].Settings .Get ("limit" ).MustString (), defaultSize ))
162171 frames = append (frames , frame )
163172
0 commit comments