2015-01-08 02:00:00 -06:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
2016-03-14 05:59:51 -05:00
|
|
|
"strconv"
|
|
|
|
|
2015-02-05 03:37:13 -06:00
|
|
|
"github.com/grafana/grafana/pkg/bus"
|
2016-06-03 10:00:39 -05:00
|
|
|
"github.com/grafana/grafana/pkg/metrics"
|
2015-02-05 03:37:13 -06:00
|
|
|
"github.com/grafana/grafana/pkg/middleware"
|
2015-06-05 01:15:38 -05:00
|
|
|
"github.com/grafana/grafana/pkg/services/search"
|
2015-01-08 02:00:00 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
func Search(c *middleware.Context) {
|
2015-02-07 09:12:29 -06:00
|
|
|
query := c.Query("query")
|
2015-06-02 03:24:20 -05:00
|
|
|
tags := c.QueryStrings("tag")
|
2015-02-04 04:35:59 -06:00
|
|
|
starred := c.Query("starred")
|
2015-02-05 04:10:56 -06:00
|
|
|
limit := c.QueryInt("limit")
|
2017-03-27 07:36:28 -05:00
|
|
|
browseMode := c.Query("browseMode")
|
2015-02-05 04:10:56 -06:00
|
|
|
|
|
|
|
if limit == 0 {
|
2015-06-02 04:04:06 -05:00
|
|
|
limit = 1000
|
2015-02-05 04:10:56 -06:00
|
|
|
}
|
2015-02-04 04:35:59 -06:00
|
|
|
|
2016-03-05 05:26:21 -06:00
|
|
|
dbids := make([]int, 0)
|
|
|
|
for _, id := range c.QueryStrings("dashboardIds") {
|
|
|
|
dashboardId, err := strconv.Atoi(id)
|
|
|
|
if err == nil {
|
|
|
|
dbids = append(dbids, dashboardId)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-13 03:45:53 -05:00
|
|
|
searchQuery := search.Query{
|
2016-03-05 05:26:21 -06:00
|
|
|
Title: query,
|
|
|
|
Tags: tags,
|
|
|
|
UserId: c.UserId,
|
|
|
|
Limit: limit,
|
|
|
|
IsStarred: starred == "true",
|
|
|
|
OrgId: c.OrgId,
|
|
|
|
DashboardIds: dbids,
|
2017-03-27 07:36:28 -05:00
|
|
|
BrowseMode: browseMode == "true",
|
2015-01-08 02:00:00 -06:00
|
|
|
}
|
|
|
|
|
2015-05-13 03:45:53 -05:00
|
|
|
err := bus.Dispatch(&searchQuery)
|
|
|
|
if err != nil {
|
|
|
|
c.JsonApiErr(500, "Search failed", err)
|
|
|
|
return
|
2015-01-08 02:00:00 -06:00
|
|
|
}
|
|
|
|
|
2016-06-03 10:00:39 -05:00
|
|
|
c.TimeRequest(metrics.M_Api_Dashboard_Search)
|
2015-05-13 03:45:53 -05:00
|
|
|
c.JSON(200, searchQuery.Result)
|
2015-01-08 02:00:00 -06:00
|
|
|
}
|