Major refactorings around searching, moved to seperate package, trying to move stuff out of models package, extend search support searching different types of entities and different types of dashboards, #960
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/bus"
|
||||
"github.com/grafana/grafana/pkg/metrics"
|
||||
m "github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/search"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -119,7 +120,7 @@ type DashboardSearchProjection struct {
|
||||
Term string
|
||||
}
|
||||
|
||||
func SearchDashboards(query *m.SearchDashboardsQuery) error {
|
||||
func SearchDashboards(query *search.FindPersistedDashboardsQuery) error {
|
||||
var sql bytes.Buffer
|
||||
params := make([]interface{}, 0)
|
||||
|
||||
@@ -166,17 +167,17 @@ func SearchDashboards(query *m.SearchDashboardsQuery) error {
|
||||
return err
|
||||
}
|
||||
|
||||
query.Result = make([]*m.DashboardSearchHit, 0)
|
||||
hits := make(map[int64]*m.DashboardSearchHit)
|
||||
query.Result = make([]*search.Hit, 0)
|
||||
hits := make(map[int64]*search.Hit)
|
||||
|
||||
for _, item := range res {
|
||||
hit, exists := hits[item.Id]
|
||||
if !exists {
|
||||
hit = &m.DashboardSearchHit{
|
||||
hit = &search.Hit{
|
||||
Id: item.Id,
|
||||
Title: item.Title,
|
||||
Uri: "db/" + item.Slug,
|
||||
Type: m.DashTypeDB,
|
||||
Type: search.DashHitDB,
|
||||
Tags: []string{},
|
||||
}
|
||||
query.Result = append(query.Result, hit)
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
|
||||
m "github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/search"
|
||||
)
|
||||
|
||||
func insertTestDashboard(title string, orgId int64, tags ...interface{}) *m.Dashboard {
|
||||
@@ -85,7 +86,7 @@ func TestDashboardDataAccess(t *testing.T) {
|
||||
})
|
||||
|
||||
Convey("Should be able to search for dashboard", func() {
|
||||
query := m.SearchDashboardsQuery{
|
||||
query := search.FindPersistedDashboardsQuery{
|
||||
Title: "test",
|
||||
OrgId: 1,
|
||||
}
|
||||
@@ -99,8 +100,8 @@ func TestDashboardDataAccess(t *testing.T) {
|
||||
})
|
||||
|
||||
Convey("Should be able to search for dashboards using tags", func() {
|
||||
query1 := m.SearchDashboardsQuery{Tag: "webapp", OrgId: 1}
|
||||
query2 := m.SearchDashboardsQuery{Tag: "tagdoesnotexist", OrgId: 1}
|
||||
query1 := search.FindPersistedDashboardsQuery{Tag: "webapp", OrgId: 1}
|
||||
query2 := search.FindPersistedDashboardsQuery{Tag: "tagdoesnotexist", OrgId: 1}
|
||||
|
||||
err := SearchDashboards(&query1)
|
||||
err = SearchDashboards(&query2)
|
||||
@@ -146,7 +147,7 @@ func TestDashboardDataAccess(t *testing.T) {
|
||||
})
|
||||
|
||||
Convey("Should be able to search for starred dashboards", func() {
|
||||
query := m.SearchDashboardsQuery{OrgId: 1, UserId: 10, IsStarred: true}
|
||||
query := search.FindPersistedDashboardsQuery{OrgId: 1, UserId: 10, IsStarred: true}
|
||||
err := SearchDashboards(&query)
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
Reference in New Issue
Block a user