Search: Avoid panic with missing title (#103257)
This commit is contained in:
@@ -46,11 +46,11 @@ func ParseResults(result *resource.ResourceSearchResponse, offset int64) (v0alph
|
||||
return v0alpha1.SearchResults{}, nil
|
||||
}
|
||||
|
||||
titleIDX := 0
|
||||
titleIDX := -1
|
||||
folderIDX := -1
|
||||
tagsIDX := -1
|
||||
scoreIDX := 0
|
||||
explainIDX := 0
|
||||
scoreIDX := -1
|
||||
explainIDX := -1
|
||||
|
||||
for i, v := range result.Results.Columns {
|
||||
switch v.Name {
|
||||
@@ -101,19 +101,24 @@ func ParseResults(result *resource.ResourceSearchResponse, offset int64) (v0alph
|
||||
hit := &v0alpha1.DashboardHit{
|
||||
Resource: row.Key.Resource, // folders | dashboards
|
||||
Name: row.Key.Name, // The Grafana UID
|
||||
Title: string(row.Cells[titleIDX]),
|
||||
Field: fields,
|
||||
}
|
||||
if folderIDX > 0 && row.Cells[folderIDX] != nil {
|
||||
if titleIDX >= 0 && row.Cells[titleIDX] != nil {
|
||||
hit.Title = string(row.Cells[titleIDX])
|
||||
} else {
|
||||
hit.Title = "(no title)"
|
||||
}
|
||||
|
||||
if folderIDX >= 0 && row.Cells[folderIDX] != nil {
|
||||
hit.Folder = string(row.Cells[folderIDX])
|
||||
}
|
||||
if tagsIDX > 0 && row.Cells[tagsIDX] != nil {
|
||||
if tagsIDX >= 0 && row.Cells[tagsIDX] != nil {
|
||||
_ = json.Unmarshal(row.Cells[tagsIDX], &hit.Tags)
|
||||
}
|
||||
if explainIDX > 0 && row.Cells[explainIDX] != nil {
|
||||
if explainIDX >= 0 && row.Cells[explainIDX] != nil {
|
||||
_ = json.Unmarshal(row.Cells[explainIDX], &hit.Explain)
|
||||
}
|
||||
if scoreIDX > 0 && row.Cells[scoreIDX] != nil {
|
||||
if scoreIDX >= 0 && row.Cells[scoreIDX] != nil {
|
||||
_, _ = binary.Decode(row.Cells[scoreIDX], binary.BigEndian, &hit.Score)
|
||||
}
|
||||
|
||||
|
||||
@@ -538,7 +538,16 @@ func (b *bleveIndex) Search(
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
searchrequest.Fields = f
|
||||
if len(f) > 0 {
|
||||
searchrequest.Fields = f
|
||||
} else {
|
||||
searchrequest.Fields = []string{
|
||||
resource.SEARCH_FIELD_TITLE,
|
||||
resource.SEARCH_FIELD_FOLDER,
|
||||
resource.SEARCH_FIELD_SOURCE_PATH,
|
||||
resource.SEARCH_FIELD_MANAGED_BY,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
res, err := index.SearchInContext(ctx, searchrequest)
|
||||
|
||||
Reference in New Issue
Block a user