[Feature] add precise search type for Elastic Search (#12869)
* feat: add type query parameters for specifying precise search * feat: add select dropdown in search box Co-authored-by: Lauris BH <lauris@nix.lv> Co-authored-by: techknowlogick <techknowlogick@gitea.io>
This commit is contained in:
parent
b2c20b68a0
commit
c10503afec
12 changed files with 77 additions and 25 deletions
|
@ -299,6 +299,9 @@ func ExploreCode(ctx *context.Context) {
|
|||
page = 1
|
||||
}
|
||||
|
||||
queryType := strings.TrimSpace(ctx.Query("t"))
|
||||
isMatch := queryType == "match"
|
||||
|
||||
var (
|
||||
repoIDs []int64
|
||||
err error
|
||||
|
@ -342,14 +345,14 @@ func ExploreCode(ctx *context.Context) {
|
|||
|
||||
ctx.Data["RepoMaps"] = rightRepoMap
|
||||
|
||||
total, searchResults, searchResultLanguages, err = code_indexer.PerformSearch(repoIDs, language, keyword, page, setting.UI.RepoSearchPagingNum)
|
||||
total, searchResults, searchResultLanguages, err = code_indexer.PerformSearch(repoIDs, language, keyword, page, setting.UI.RepoSearchPagingNum, isMatch)
|
||||
if err != nil {
|
||||
ctx.ServerError("SearchResults", err)
|
||||
return
|
||||
}
|
||||
// if non-login user or isAdmin, no need to check UnitTypeCode
|
||||
} else if (ctx.User == nil && len(repoIDs) > 0) || isAdmin {
|
||||
total, searchResults, searchResultLanguages, err = code_indexer.PerformSearch(repoIDs, language, keyword, page, setting.UI.RepoSearchPagingNum)
|
||||
total, searchResults, searchResultLanguages, err = code_indexer.PerformSearch(repoIDs, language, keyword, page, setting.UI.RepoSearchPagingNum, isMatch)
|
||||
if err != nil {
|
||||
ctx.ServerError("SearchResults", err)
|
||||
return
|
||||
|
@ -380,6 +383,7 @@ func ExploreCode(ctx *context.Context) {
|
|||
|
||||
ctx.Data["Keyword"] = keyword
|
||||
ctx.Data["Language"] = language
|
||||
ctx.Data["queryType"] = queryType
|
||||
ctx.Data["SearchResults"] = searchResults
|
||||
ctx.Data["SearchResultLanguages"] = searchResultLanguages
|
||||
ctx.Data["RequireHighlightJS"] = true
|
||||
|
|
|
@ -28,14 +28,18 @@ func Search(ctx *context.Context) {
|
|||
if page <= 0 {
|
||||
page = 1
|
||||
}
|
||||
queryType := strings.TrimSpace(ctx.Query("t"))
|
||||
isMatch := queryType == "match"
|
||||
|
||||
total, searchResults, searchResultLanguages, err := code_indexer.PerformSearch([]int64{ctx.Repo.Repository.ID},
|
||||
language, keyword, page, setting.UI.RepoSearchPagingNum)
|
||||
language, keyword, page, setting.UI.RepoSearchPagingNum, isMatch)
|
||||
if err != nil {
|
||||
ctx.ServerError("SearchResults", err)
|
||||
return
|
||||
}
|
||||
ctx.Data["Keyword"] = keyword
|
||||
ctx.Data["Language"] = language
|
||||
ctx.Data["queryType"] = queryType
|
||||
ctx.Data["SourcePath"] = setting.AppSubURL + "/" +
|
||||
path.Join(ctx.Repo.Repository.Owner.Name, ctx.Repo.Repository.Name)
|
||||
ctx.Data["SearchResults"] = searchResults
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue