예제 #1
0
// Get implemented Get method for SearchRouter.
func (this *SearchRouter) Get() {
	this.TplNames = "search.html"

	// Get argument(s).
	q := strings.TrimSpace(this.Input().Get("q"))
	t := strings.TrimSpace(this.Input().Get("t"))
	pid := strings.TrimSpace(this.Input().Get("pid"))
	tag := strings.TrimSpace(this.Input().Get("tag"))
	if tag == "master" || tag == "default" {
		tag = ""
	}

	if len(q) == 0 {
		this.Redirect("/", 302)
		return
	}

	this.Data["Keyword"] = q

	if checkSpecialUsage(this, q, t, pid, tag) {
		return
	}

	pinfos := models.SearchPkg(q, -1, -1, -1, -1, true)
	if len(pinfos) > 0 {
		this.Data["IsFindPro"] = true
		this.Data["Results"] = pinfos
		this.Data["ResultCount"] = len(pinfos)
	}
}
예제 #2
0
파일: api.go 프로젝트: NicholeGit/gowalker
func (this *ApiRouter) Search() {
	var result struct {
		Packages []hv.PkgInfo `json:"packages"`
	}
	result.Packages = models.SearchPkg(this.GetString("key"),
		parseParaToInt(this.GetString("cmd")), parseParaToInt(this.GetString("cgo")),
		parseParaToInt(this.GetString("gorepo")), parseParaToInt(this.GetString("gosubrepo")),
		false)
	this.Data["json"] = &result
	this.ServeJson(true)
}
예제 #3
0
파일: search.go 프로젝트: JoeyFan/gowalker
// Get implemented Get method for SearchRouter.
func (this *SearchRouter) Get() {
	// Set language version.
	curLang := globalSetting(this.Ctx, this.Input(), this.Data)

	// Get argument(s).
	q := strings.TrimSpace(this.Input().Get("q"))

	// Empty query string shows home page.
	if len(q) == 0 {
		this.Redirect("/", 302)
		return
	}

	// Set properties.
	this.TplNames = "search_" + curLang.Lang + ".html"
	this.Data["Keyword"] = q
	this.Data["DataSrc"] = utils.GoRepoSet

	if checkSpecialUsage(this, q) {
		return
	}

	// Remove last "/" and check path.
	if path, ok := utils.IsBrowseURL(
		strings.TrimRight(q, "/")); ok {
		q = path
	}

	// // Check if print raw page.
	// if this.Input().Get("raw") == "true" {
	// 	// Check if need to match sub-packages.
	// 	isMatchSub := false
	// 	if this.Input().Get("sub") == "true" {
	// 		isMatchSub = true
	// 	}

	// 	pinfos, _ := models.SearchRawDoc(q, isMatchSub)
	// 	var buf bytes.Buffer
	// 	for _, p := range pinfos {
	// 		buf.WriteString(p.Path + "$" + p.Synopsis + "|||")
	// 	}
	// 	this.Ctx.WriteString(buf.String())
	// 	return
	// }

	pinfos := models.SearchPkg(q)
	if len(pinfos) > 0 {
		this.Data["IsFindPro"] = true
		this.Data["Results"] = pinfos
	}
}