@@ -95,11 +95,30 @@ 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+ 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+
98115func processLogsResponse (res * es.SearchResponse , target * Query , configuredFields es.ConfiguredFields , queryRes * backend.DataResponse ) error {
99116 propNames := make (map [string ]bool )
100117 docs := make ([]map [string ]interface {}, len (res .Hits .Hits ))
101118 searchWords := make (map [string ]bool )
102119
120+ highlights := parseLuceneQuery (target .RawQuery )
121+
103122 for hitIdx , hit := range res .Hits .Hits {
104123 var flattened map [string ]interface {}
105124 if hit ["_source" ] != nil {
@@ -132,23 +151,6 @@ func processLogsResponse(res *es.SearchResponse, target *Query, configuredFields
132151 propNames [key ] = true
133152 }
134153
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-
152154 docs [hitIdx ] = doc
153155 }
154156
@@ -158,6 +160,11 @@ func processLogsResponse(res *es.SearchResponse, target *Query, configuredFields
158160 frames := data.Frames {}
159161 frame := data .NewFrame ("" , fields ... )
160162 setPreferredVisType (frame , data .VisTypeLogs )
163+
164+ for _ , keyword := range highlights {
165+ searchWords [keyword ] = true
166+ }
167+
161168 setLogsCustomMeta (frame , searchWords , stringToIntWithDefaultValue (target .Metrics [0 ].Settings .Get ("limit" ).MustString (), defaultSize ))
162169 frames = append (frames , frame )
163170
0 commit comments