mirror of
https://github.com/grafana/grafana.git
synced 2024-11-26 02:40:26 -06:00
39 lines
728 B
Go
39 lines
728 B
Go
package api
|
|
|
|
import (
|
|
"github.com/grafana/grafana/pkg/bus"
|
|
"github.com/grafana/grafana/pkg/live"
|
|
"github.com/grafana/grafana/pkg/middleware"
|
|
"github.com/grafana/grafana/pkg/services/search"
|
|
)
|
|
|
|
func Search(c *middleware.Context) {
|
|
query := c.Query("query")
|
|
tags := c.QueryStrings("tag")
|
|
starred := c.Query("starred")
|
|
limit := c.QueryInt("limit")
|
|
|
|
if limit == 0 {
|
|
limit = 1000
|
|
}
|
|
|
|
searchQuery := search.Query{
|
|
Title: query,
|
|
Tags: tags,
|
|
UserId: c.UserId,
|
|
Limit: limit,
|
|
IsStarred: starred == "true",
|
|
OrgId: c.OrgId,
|
|
}
|
|
|
|
err := bus.Dispatch(&searchQuery)
|
|
if err != nil {
|
|
c.JsonApiErr(500, "Search failed", err)
|
|
return
|
|
}
|
|
|
|
c.JSON(200, searchQuery.Result)
|
|
|
|
live.SendMessage(query)
|
|
}
|