suggest.go 828 B

123456789101112131415161718192021222324252627282930313233343536
  1. package route
  2. import (
  3. "github.com/G-Node/gogs/internal/context"
  4. "github.com/G-Node/libgin/libgin"
  5. log "gopkg.in/clog.v1"
  6. )
  7. // ExploreSuggest returns suggestions for keywords to fill the search box on the explore/data page.
  8. func ExploreSuggest(c *context.Context) {
  9. keywords := c.Params(":keywords")
  10. sType := libgin.SEARCH_SUGGEST
  11. log.Trace("Suggestions for [%s]", keywords)
  12. if keywords == "" {
  13. // no keywords submitted: return
  14. return
  15. }
  16. // res := libgin.SearchResults{}
  17. log.Trace("Searching data/blobs for suggestions")
  18. data, err := search(c, keywords, sType)
  19. if err != nil {
  20. log.Error(2, "Query returned error: %v", err)
  21. return
  22. }
  23. log.Trace("Returning suggestions: %+v", string(data))
  24. if err != nil {
  25. log.Error(2, "Failed to marshal structured suggestions: %v", err)
  26. return
  27. }
  28. c.Write(data)
  29. }