summaryrefslogtreecommitdiffstats
path: root/routers/web/repo/search.go
diff options
context:
space:
mode:
Diffstat (limited to 'routers/web/repo/search.go')
-rw-r--r--routers/web/repo/search.go22
1 files changed, 16 insertions, 6 deletions
diff --git a/routers/web/repo/search.go b/routers/web/repo/search.go
index 8f141cb149..3d1835c7c3 100644
--- a/routers/web/repo/search.go
+++ b/routers/web/repo/search.go
@@ -21,14 +21,27 @@ func Search(ctx *context.Context) {
ctx.Redirect(ctx.Repo.RepoLink)
return
}
+
language := ctx.FormTrim("l")
keyword := ctx.FormTrim("q")
+
+ queryType := ctx.FormTrim("t")
+ isMatch := queryType == "match"
+
+ ctx.Data["Keyword"] = keyword
+ ctx.Data["Language"] = language
+ ctx.Data["queryType"] = queryType
+ ctx.Data["PageIsViewCode"] = true
+
+ if keyword == "" {
+ ctx.HTML(http.StatusOK, tplSearch)
+ return
+ }
+
page := ctx.FormInt("page")
if page <= 0 {
page = 1
}
- queryType := ctx.FormTrim("t")
- isMatch := queryType == "match"
total, searchResults, searchResultLanguages, err := code_indexer.PerformSearch(ctx, []int64{ctx.Repo.Repository.ID},
language, keyword, page, setting.UI.RepoSearchPagingNum, isMatch)
@@ -41,13 +54,10 @@ func Search(ctx *context.Context) {
} else {
ctx.Data["CodeIndexerUnavailable"] = !code_indexer.IsAvailable()
}
- ctx.Data["Keyword"] = keyword
- ctx.Data["Language"] = language
- ctx.Data["queryType"] = queryType
+
ctx.Data["SourcePath"] = ctx.Repo.Repository.HTMLURL()
ctx.Data["SearchResults"] = searchResults
ctx.Data["SearchResultLanguages"] = searchResultLanguages
- ctx.Data["PageIsViewCode"] = true
pager := context.NewPagination(total, setting.UI.RepoSearchPagingNum, page, 5)
pager.SetDefaultParams(ctx)