grafana/pkg/api/search.go

51 lines
1.0 KiB
Go
Raw Normal View History

2015-01-08 02:00:00 -06:00
package api
import (
"strconv"
2015-02-05 03:37:13 -06:00
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/metrics"
2015-02-05 03:37:13 -06:00
"github.com/grafana/grafana/pkg/middleware"
"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")
tags := c.QueryStrings("tag")
starred := c.Query("starred")
limit := c.QueryInt("limit")
browseMode := c.Query("browseMode")
if limit == 0 {
limit = 1000
}
dbids := make([]int, 0)
for _, id := range c.QueryStrings("dashboardIds") {
dashboardId, err := strconv.Atoi(id)
if err == nil {
dbids = append(dbids, dashboardId)
}
}
searchQuery := search.Query{
Title: query,
Tags: tags,
UserId: c.UserId,
Limit: limit,
IsStarred: starred == "true",
OrgId: c.OrgId,
DashboardIds: dbids,
BrowseMode: browseMode == "true",
2015-01-08 02:00:00 -06:00
}
err := bus.Dispatch(&searchQuery)
if err != nil {
c.JsonApiErr(500, "Search failed", err)
return
2015-01-08 02:00:00 -06:00
}
c.TimeRequest(metrics.M_Api_Dashboard_Search)
c.JSON(200, searchQuery.Result)
2015-01-08 02:00:00 -06:00
}