You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.6 KiB
56 lines
1.6 KiB
7 years ago
|
// Copyright 2017 The Gitea Authors. All rights reserved.
|
||
|
// Use of this source code is governed by a MIT-style
|
||
|
// license that can be found in the LICENSE file.
|
||
|
|
||
|
package repo
|
||
|
|
||
|
import (
|
||
4 years ago
|
"net/http"
|
||
7 years ago
|
"strings"
|
||
|
|
||
|
"code.gitea.io/gitea/modules/base"
|
||
|
"code.gitea.io/gitea/modules/context"
|
||
5 years ago
|
code_indexer "code.gitea.io/gitea/modules/indexer/code"
|
||
7 years ago
|
"code.gitea.io/gitea/modules/setting"
|
||
|
)
|
||
|
|
||
|
const tplSearch base.TplName = "repo/search"
|
||
|
|
||
|
// Search render repository search page
|
||
|
func Search(ctx *context.Context) {
|
||
|
if !setting.Indexer.RepoIndexerEnabled {
|
||
|
ctx.Redirect(ctx.Repo.RepoLink, 302)
|
||
|
return
|
||
|
}
|
||
5 years ago
|
language := strings.TrimSpace(ctx.Query("l"))
|
||
7 years ago
|
keyword := strings.TrimSpace(ctx.Query("q"))
|
||
|
page := ctx.QueryInt("page")
|
||
|
if page <= 0 {
|
||
|
page = 1
|
||
|
}
|
||
4 years ago
|
queryType := strings.TrimSpace(ctx.Query("t"))
|
||
|
isMatch := queryType == "match"
|
||
|
|
||
5 years ago
|
total, searchResults, searchResultLanguages, err := code_indexer.PerformSearch([]int64{ctx.Repo.Repository.ID},
|
||
4 years ago
|
language, keyword, page, setting.UI.RepoSearchPagingNum, isMatch)
|
||
7 years ago
|
if err != nil {
|
||
7 years ago
|
ctx.ServerError("SearchResults", err)
|
||
7 years ago
|
return
|
||
|
}
|
||
|
ctx.Data["Keyword"] = keyword
|
||
5 years ago
|
ctx.Data["Language"] = language
|
||
4 years ago
|
ctx.Data["queryType"] = queryType
|
||
4 years ago
|
ctx.Data["SourcePath"] = ctx.Repo.Repository.HTMLURL()
|
||
7 years ago
|
ctx.Data["SearchResults"] = searchResults
|
||
5 years ago
|
ctx.Data["SearchResultLanguages"] = searchResultLanguages
|
||
7 years ago
|
ctx.Data["RequireHighlightJS"] = true
|
||
|
ctx.Data["PageIsViewCode"] = true
|
||
6 years ago
|
|
||
|
pager := context.NewPagination(total, setting.UI.RepoSearchPagingNum, page, 5)
|
||
|
pager.SetDefaultParams(ctx)
|
||
5 years ago
|
pager.AddParam(ctx, "l", "Language")
|
||
6 years ago
|
ctx.Data["Page"] = pager
|
||
|
|
||
4 years ago
|
ctx.HTML(http.StatusOK, tplSearch)
|
||
7 years ago
|
}
|