mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
Improve issue & code search (#33860)
Each "indexer" should provide the "search modes" they support by themselves. And we need to remove the "fuzzy" search for code.
This commit is contained in:
@@ -72,10 +72,10 @@ func Code(ctx *context.Context) {
|
||||
|
||||
if (len(repoIDs) > 0) || isAdmin {
|
||||
total, searchResults, searchResultLanguages, err = code_indexer.PerformSearch(ctx, &code_indexer.SearchOptions{
|
||||
RepoIDs: repoIDs,
|
||||
Keyword: prepareSearch.Keyword,
|
||||
IsKeywordFuzzy: prepareSearch.IsFuzzy,
|
||||
Language: prepareSearch.Language,
|
||||
RepoIDs: repoIDs,
|
||||
Keyword: prepareSearch.Keyword,
|
||||
SearchMode: prepareSearch.SearchMode,
|
||||
Language: prepareSearch.Language,
|
||||
Paginator: &db.ListOptions{
|
||||
Page: page,
|
||||
PageSize: setting.UI.RepoSearchPagingNum,
|
||||
|
@@ -38,10 +38,10 @@ func Search(ctx *context.Context) {
|
||||
if setting.Indexer.RepoIndexerEnabled {
|
||||
var err error
|
||||
total, searchResults, searchResultLanguages, err = code_indexer.PerformSearch(ctx, &code_indexer.SearchOptions{
|
||||
RepoIDs: []int64{ctx.Repo.Repository.ID},
|
||||
Keyword: prepareSearch.Keyword,
|
||||
IsKeywordFuzzy: prepareSearch.IsFuzzy,
|
||||
Language: prepareSearch.Language,
|
||||
RepoIDs: []int64{ctx.Repo.Repository.ID},
|
||||
Keyword: prepareSearch.Keyword,
|
||||
SearchMode: prepareSearch.SearchMode,
|
||||
Language: prepareSearch.Language,
|
||||
Paginator: &db.ListOptions{
|
||||
Page: page,
|
||||
PageSize: setting.UI.RepoSearchPagingNum,
|
||||
@@ -60,7 +60,7 @@ func Search(ctx *context.Context) {
|
||||
var err error
|
||||
// ref should be default branch or the first existing branch
|
||||
searchRef := git.RefNameFromBranch(ctx.Repo.Repository.DefaultBranch)
|
||||
searchResults, total, err = gitgrep.PerformSearch(ctx, page, ctx.Repo.Repository.ID, ctx.Repo.GitRepo, searchRef, prepareSearch.Keyword, prepareSearch.IsFuzzy)
|
||||
searchResults, total, err = gitgrep.PerformSearch(ctx, page, ctx.Repo.Repository.ID, ctx.Repo.GitRepo, searchRef, prepareSearch.Keyword, prepareSearch.SearchMode)
|
||||
if err != nil {
|
||||
ctx.ServerError("gitgrep.PerformSearch", err)
|
||||
return
|
||||
|
@@ -68,10 +68,10 @@ func CodeSearch(ctx *context.Context) {
|
||||
|
||||
if len(repoIDs) > 0 {
|
||||
total, searchResults, searchResultLanguages, err = code_indexer.PerformSearch(ctx, &code_indexer.SearchOptions{
|
||||
RepoIDs: repoIDs,
|
||||
Keyword: prepareSearch.Keyword,
|
||||
IsKeywordFuzzy: prepareSearch.IsFuzzy,
|
||||
Language: prepareSearch.Language,
|
||||
RepoIDs: repoIDs,
|
||||
Keyword: prepareSearch.Keyword,
|
||||
SearchMode: prepareSearch.SearchMode,
|
||||
Language: prepareSearch.Language,
|
||||
Paginator: &db.ListOptions{
|
||||
Page: page,
|
||||
PageSize: setting.UI.RepoSearchPagingNum,
|
||||
|
@@ -26,6 +26,7 @@ import (
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/base"
|
||||
"code.gitea.io/gitea/modules/container"
|
||||
"code.gitea.io/gitea/modules/indexer"
|
||||
issue_indexer "code.gitea.io/gitea/modules/indexer/issues"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/markup/markdown"
|
||||
@@ -447,7 +448,7 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
|
||||
ctx.Data["FilterAssigneeUsername"] = assigneeUsername
|
||||
opts.AssigneeID = user.GetFilterUserIDByName(ctx, assigneeUsername)
|
||||
|
||||
isFuzzy := ctx.FormBool("fuzzy")
|
||||
searchMode := ctx.FormString("search_mode")
|
||||
|
||||
// Search all repositories which
|
||||
//
|
||||
@@ -549,7 +550,9 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
|
||||
var issues issues_model.IssueList
|
||||
{
|
||||
issueIDs, _, err := issue_indexer.SearchIssues(ctx, issue_indexer.ToSearchOptions(keyword, opts).Copy(
|
||||
func(o *issue_indexer.SearchOptions) { o.IsFuzzyKeyword = isFuzzy },
|
||||
func(o *issue_indexer.SearchOptions) {
|
||||
o.SearchMode = indexer.SearchModeType(searchMode)
|
||||
},
|
||||
))
|
||||
if err != nil {
|
||||
ctx.ServerError("issueIDsFromSearch", err)
|
||||
@@ -578,7 +581,7 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
|
||||
// -------------------------------
|
||||
issueStats, err := getUserIssueStats(ctx, ctxUser, filterMode, issue_indexer.ToSearchOptions(keyword, opts).Copy(
|
||||
func(o *issue_indexer.SearchOptions) {
|
||||
o.IsFuzzyKeyword = isFuzzy
|
||||
o.SearchMode = indexer.SearchModeType(searchMode)
|
||||
},
|
||||
))
|
||||
if err != nil {
|
||||
@@ -633,7 +636,8 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
|
||||
ctx.Data["ViewType"] = viewType
|
||||
ctx.Data["SortType"] = sortType
|
||||
ctx.Data["IsShowClosed"] = isShowClosed
|
||||
ctx.Data["IsFuzzy"] = isFuzzy
|
||||
ctx.Data["SearchModes"] = issue_indexer.SupportedSearchModes()
|
||||
ctx.Data["SelectedSearchMode"] = ctx.FormTrim("search_mode")
|
||||
|
||||
if isShowClosed {
|
||||
ctx.Data["State"] = "closed"
|
||||
|
Reference in New Issue
Block a user