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

	if ctx.Query("auto_redirect") == "true" &&
		(base.IsGoRepoPath(q) || base.IsGAERepoPath(q) ||
			base.IsValidRemotePath(q)) {
		ctx.Redirect("/" + q)
		return
	}

	var (
		results []*models.PkgInfo
		err     error
	)
	switch q {
	case "gorepos":
		results, err = models.GetGoRepos()
	case "gosubrepos":
		results, err = models.GetGoSubepos()
	case "gaesdk":
		results, err = models.GetGAERepos()
	default:
		results, err = models.SearchPkgInfo(100, q)
	}
	if err != nil {
		ctx.Flash.Error(err.Error(), true)
	} else {
		ctx.Data["Results"] = results
	}

	ctx.Data["Keyword"] = q
	ctx.HTML(200, SEARCH)
}
Exemple #2
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,
	})
}
Exemple #3
0
func Search(ctx *middleware.Context) {
	q := ctx.Query("q")

	if ctx.Query("auto_redirect") == "true" &&
		(base.IsGoRepoPath(q) || base.IsValidRemotePath(q)) {
		ctx.Redirect("/" + q)
		return
	}

	results, err := models.SearchPkgInfo(100, q)
	if err != nil {
		ctx.Flash.Error(err.Error(), true)
	} else {
		ctx.Data["Results"] = results
	}

	ctx.Data["Keyword"] = q
	ctx.HTML(200, SEARCH)
}