Refactor search (#23550)

Co-Authored-By: Arve Knudsen <arve.knudsen@grafana.com>
Co-Authored-By: Leonard Gram <leonard.gram@grafana.com>
This commit is contained in:
Emil Tullstedt
2020-04-20 16:20:45 +02:00
committed by GitHub
co-authored by Arve Knudsen Leonard Gram
parent e5dd7efdee
commit 55c306eb6d
13 changed files with 778 additions and 16 deletions
+1
View File
@@ -330,6 +330,7 @@ func (hs *HTTPServer) registerRoutes() {
})
// Search
apiRoute.Get("/search/sorting", Wrap(hs.ListSortOptions))
apiRoute.Get("/search/", Wrap(Search))
// metrics
+2
View File
@@ -4,6 +4,7 @@ import (
"context"
"crypto/tls"
"fmt"
"github.com/grafana/grafana/pkg/services/search"
"net"
"net/http"
"os"
@@ -67,6 +68,7 @@ type HTTPServer struct {
License models.Licensing `inject:""`
BackendPluginManager backendplugin.Manager `inject:""`
PluginManager *plugins.PluginManager `inject:""`
SearchService *search.SearchService `inject:""`
}
func (hs *HTTPServer) Init() error {
+21
View File
@@ -1,6 +1,8 @@
package api
import (
"github.com/grafana/grafana/pkg/util"
"net/http"
"strconv"
"github.com/grafana/grafana/pkg/bus"
@@ -16,6 +18,7 @@ func Search(c *models.ReqContext) Response {
limit := c.QueryInt64("limit")
page := c.QueryInt64("page")
dashboardType := c.Query("type")
sort := c.Query("sort")
permission := models.PERMISSION_VIEW
if limit > 5000 {
@@ -54,6 +57,7 @@ func Search(c *models.ReqContext) Response {
Type: dashboardType,
FolderIds: folderIDs,
Permission: permission,
Sort: sort,
}
err := bus.Dispatch(&searchQuery)
@@ -64,3 +68,20 @@ func Search(c *models.ReqContext) Response {
c.TimeRequest(metrics.MApiDashboardSearch)
return JSON(200, searchQuery.Result)
}
func (hs *HTTPServer) ListSortOptions(c *models.ReqContext) Response {
opts := hs.SearchService.SortOptions()
res := []util.DynMap{}
for _, o := range opts {
res = append(res, util.DynMap{
"name": o.Name,
"displayName": o.DisplayName,
"description": o.Description,
})
}
return JSON(http.StatusOK, util.DynMap{
"sortOptions": res,
})
}