Example #1
0
func SearchJSON(ctx *middleware.Context) {
	q := ctx.Query("q")

	// Clean up keyword.
	q = strings.TrimFunc(q, func(c rune) bool {
		return unicode.IsSpace(c) || c == '"'
	})
	fmt.Println(q)

	pinfos, err := models.SearchPkgInfo(7, q)
	if err != nil {
		log.ErrorD(4, "SearchPkgInfo '%s': %v", q, err)
		return
	}

	results := make([]*searchResult, len(pinfos))
	for i := range pinfos {
		results[i] = &searchResult{
			Title:       pinfos[i].ImportPath,
			Description: pinfos[i].Synopsis,
		}
	}

	ctx.JSON(200, map[string]interface{}{
		"results": results,
	})
}
Example #2
0
func SearchJSON(ctx *middleware.Context) {
	q := ctx.QueryEscape("q")
	pinfos, err := models.SearchPkgInfo(7, q)
	if err != nil {
		log.ErrorD(4, "SearchPkgInfo '%s': %v", q, err)
		return
	}

	results := make([]*searchResult, len(pinfos))
	for i := range pinfos {
		results[i] = &searchResult{
			Title:       pinfos[i].ImportPath,
			Description: pinfos[i].Synopsis,
		}
	}

	ctx.JSON(200, map[string]interface{}{
		"results": results,
	})
}