Dashboard search by tag, and tag cloud now works, god dam I hate SQL

This commit is contained in:
Torkel Ödegaard
2015-01-07 12:37:24 +01:00
parent bcdbec61d7
commit 1ae52d2472
6 changed files with 126 additions and 40 deletions
+10 -4
View File
@@ -1,6 +1,7 @@
package api
import (
"regexp"
"strings"
"github.com/torkelo/grafana-pro/pkg/bus"
@@ -49,8 +50,8 @@ func DeleteDashboard(c *middleware.Context) {
func Search(c *middleware.Context) {
queryText := c.Query("q")
result := m.SearchResult{
Dashboards: []m.DashboardSearchHit{},
Tags: []m.DashboardTagCloudItem{},
Dashboards: []*m.DashboardSearchHit{},
Tags: []*m.DashboardTagCloudItem{},
}
if strings.HasPrefix(queryText, "tags!:") {
@@ -63,8 +64,13 @@ func Search(c *middleware.Context) {
result.Tags = query.Result
result.TagsOnly = true
} else {
queryText := strings.TrimPrefix(queryText, "title:")
query := m.SearchDashboardsQuery{Query: queryText, AccountId: c.GetAccountId()}
searchQueryRegEx, _ := regexp.Compile(`(tags:(\w*)\sAND\s)?(?:title:)?(.*)?`)
matches := searchQueryRegEx.FindStringSubmatch(queryText)
query := m.SearchDashboardsQuery{
Title: matches[3],
Tag: matches[2],
AccountId: c.GetAccountId(),
}
err := bus.Dispatch(&query)
if err != nil {
c.JsonApiErr(500, "Search failed", err)