Dashboard list panel: Now supports search by multiple tags, Closes #2096

This commit is contained in:
Torkel Ödegaard
2015-06-02 11:04:06 +02:00
parent 6df9012141
commit 50a1feb90a
9 changed files with 29 additions and 18 deletions
+1 -1
View File
@@ -13,7 +13,7 @@ func Search(c *middleware.Context) {
limit := c.QueryInt("limit")
if limit == 0 {
limit = 200
limit = 1000
}
searchQuery := search.Query{
+9 -4
View File
@@ -1,6 +1,7 @@
package search
import (
"fmt"
"path/filepath"
"sort"
@@ -34,7 +35,6 @@ func searchHandler(query *Query) error {
dashQuery := FindPersistedDashboardsQuery{
Title: query.Title,
UserId: query.UserId,
Limit: query.Limit,
IsStarred: query.IsStarred,
OrgId: query.OrgId,
}
@@ -65,6 +65,14 @@ func searchHandler(query *Query) error {
hits = filtered
}
// sort main result array
sort.Sort(hits)
fmt.Printf("Length: %d", len(hits))
if len(hits) > query.Limit {
hits = hits[0 : query.Limit-1]
}
// sort tags
for _, hit := range hits {
sort.Strings(hit.Tags)
@@ -75,9 +83,6 @@ func searchHandler(query *Query) error {
return err
}
// sort main result array
sort.Sort(hits)
query.Result = hits
return nil
}
+1 -1
View File
@@ -12,7 +12,7 @@ func TestSearch(t *testing.T) {
Convey("Given search query", t, func() {
jsonDashIndex = NewJsonDashIndex("../../public/dashboards/")
query := Query{}
query := Query{Limit: 2000}
bus.AddHandler("test", func(query *FindPersistedDashboardsQuery) error {
query.Result = HitList{
-1
View File
@@ -39,7 +39,6 @@ type FindPersistedDashboardsQuery struct {
Title string
OrgId int64
UserId int64
Limit int
IsStarred bool
Result HitList
+1 -5
View File
@@ -150,11 +150,7 @@ func SearchDashboards(query *search.FindPersistedDashboardsQuery) error {
params = append(params, "%"+query.Title+"%")
}
if query.Limit == 0 || query.Limit > 10000 {
query.Limit = 1000
}
sql.WriteString(fmt.Sprintf(" ORDER BY dashboard.title ASC LIMIT %d", query.Limit))
sql.WriteString(fmt.Sprintf(" ORDER BY dashboard.title ASC LIMIT 1000"))
var res []DashboardSearchProjection
err := x.Sql(sql.String(), params...).Find(&res)