コード例 #1
0
ファイル: search.go プロジェクト: seacoastboy/gowalker
// Get implemented Get method for SearchRouter.
func (this *SearchRouter) Get() {
	// Set language version.
	curLang := setLangVer(this.Ctx, this.Input(), this.Data)

	// Get arguments.
	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
	// Set standard library keyword type-ahead.
	this.Data["DataSrc"] = utils.GoRepoSet

	if checkSpecialUsage(this, q) {
		return
	}

	// Remove last "/".
	q = strings.TrimRight(q, "/")
	if path, ok := utils.IsBrowseURL(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
	// 	}

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

	// Returns a slice of results.
	pkgInfos, _ := models.SearchDoc(q)

	// Show results after searched.
	if len(pkgInfos) > 0 {
		this.Data["IsFindPro"] = true
		this.Data["AllPros"] = pkgInfos
	}
}
コード例 #2
0
ファイル: search.go プロジェクト: skelterjohn/gowalker
// Get implemented Get method for SearchController.
// It serves search page of Go Walker.
func (this *SearchController) Get() {
	// Check language version by different ways.
	lang := checkLangVer(this.Ctx.Request, this.Input().Get("lang"))

	// Get language version.
	curLang, restLangs := getLangVer(
		this.Ctx.Request.Header.Get("Accept-Language"), lang)

	// Save language information in cookies.
	this.Ctx.SetCookie("lang", curLang.Lang+";path=/", 0)

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

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

	// Set properties.
	this.Layout = "layout_" + curLang.Lang + ".html"
	this.TplNames = "search_" + curLang.Lang + ".html"

	this.Data["Keyword"] = q
	// Set standard library keyword type-ahead.
	this.Data["DataSrc"] = utils.GoRepoSet
	// Set language properties.
	this.Data["Lang"] = curLang.Lang
	this.Data["CurLang"] = curLang.Name
	this.Data["RestLangs"] = restLangs

	if checkSpecialUsage(this, q) {
		return
	}

	if path, ok := utils.IsBrowseURL(q); ok {
		q = path
	}

	// Returns a slice of results.
	pkgInfos, _ := models.SearchDoc(q)
	// Show results after searched.
	if len(pkgInfos) > 0 {
		this.Data["IsFindPro"] = true
		this.Data["AllPros"] = pkgInfos
	}
}
コード例 #3
0
ファイル: search.go プロジェクト: richardjoo/gowalker
// Get implemented Get method for SearchController.
// It serves search page of Go Walker.
func (this *SearchController) Get() {
	// Set language version.
	curLang, restLangs := setLangVer(this.Ctx.Request, this.Input())

	// Save language information in cookies.
	this.Ctx.SetCookie("lang", curLang.Lang+";path=/", 0)

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

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

	// Set properties.
	this.Layout = "layout_" + curLang.Lang + ".html"
	this.TplNames = "search_" + curLang.Lang + ".html"

	this.Data["Keyword"] = q
	// Set standard library keyword type-ahead.
	this.Data["DataSrc"] = utils.GoRepoSet
	// Set language properties.
	this.Data["Lang"] = curLang.Lang
	this.Data["CurLang"] = curLang.Name
	this.Data["RestLangs"] = restLangs

	if checkSpecialUsage(this, q) {
		return
	}

	if path, ok := utils.IsBrowseURL(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
		}

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

	// Returns a slice of results.
	pkgInfos, _ := models.SearchDoc(q)

	// Show results after searched.
	if len(pkgInfos) > 0 {
		this.Data["IsFindPro"] = true
		this.Data["AllPros"] = pkgInfos
	}
}