From be5be0ac81ce50ad5adb079af6ca4e8c396aaece Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Thu, 18 Apr 2024 02:16:52 +0200 Subject: [PATCH] Expose fuzzy search for issues/pulls (#29701) close #29685 --------- Signed-off-by: 6543 <6543@obermui.de> Co-authored-by: silverwind --- options/locale/locale_en-US.ini | 6 +++-- routers/web/user/home.go | 12 +++++++-- templates/shared/search/fuzzy.tmpl | 4 +-- templates/user/dashboard/issues.tmpl | 40 +++++++++++++++------------- web_src/css/form.css | 2 +- 5 files changed, 38 insertions(+), 26 deletions(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index a7c1d91791673..c602aba53dc5f 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -164,8 +164,8 @@ search = Search... type_tooltip = Search type fuzzy = Fuzzy fuzzy_tooltip = Include results that also match the search term closely -match = Match -match_tooltip = Include only results that match the exact search term +exact = Exact +exact_tooltip = Include only results that match the exact search term repo_kind = Search repos... user_kind = Search users... org_kind = Search orgs... @@ -179,6 +179,8 @@ branch_kind = Search branches... commit_kind = Search commits... runner_kind = Search runners... no_results = No matching results found. +issue_kind = Search issues... +pull_kind = Search pulls... keyword_search_unavailable = Searching by keyword is currently not available. Please contact the site administrator. [aria] diff --git a/routers/web/user/home.go b/routers/web/user/home.go index ff6c2a6c36dd5..c3f34039e9c3c 100644 --- a/routers/web/user/home.go +++ b/routers/web/user/home.go @@ -447,6 +447,8 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) { User: ctx.Doer, } + isFuzzy := ctx.FormBool("fuzzy") + // Search all repositories which // // As user: @@ -546,7 +548,9 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) { // USING FINAL STATE OF opts FOR A QUERY. var issues issues_model.IssueList { - issueIDs, _, err := issue_indexer.SearchIssues(ctx, issue_indexer.ToSearchOptions(keyword, opts)) + issueIDs, _, err := issue_indexer.SearchIssues(ctx, issue_indexer.ToSearchOptions(keyword, opts).Copy( + func(o *issue_indexer.SearchOptions) { o.IsFuzzyKeyword = isFuzzy }, + )) if err != nil { ctx.ServerError("issueIDsFromSearch", err) return @@ -567,7 +571,9 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) { // ------------------------------- // Fill stats to post to ctx.Data. // ------------------------------- - issueStats, err := getUserIssueStats(ctx, ctxUser, filterMode, issue_indexer.ToSearchOptions(keyword, opts)) + issueStats, err := getUserIssueStats(ctx, ctxUser, filterMode, issue_indexer.ToSearchOptions(keyword, opts).Copy( + func(o *issue_indexer.SearchOptions) { o.IsFuzzyKeyword = isFuzzy }, + )) if err != nil { ctx.ServerError("getUserIssueStats", err) return @@ -621,6 +627,7 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) { ctx.Data["SortType"] = sortType ctx.Data["IsShowClosed"] = isShowClosed ctx.Data["SelectLabels"] = selectedLabels + ctx.Data["IsFuzzy"] = isFuzzy if isShowClosed { ctx.Data["State"] = "closed" @@ -634,6 +641,7 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) { pager.AddParamString("sort", sortType) pager.AddParamString("state", fmt.Sprint(ctx.Data["State"])) pager.AddParamString("labels", selectedLabels) + pager.AddParamString("fuzzy", fmt.Sprintf("%v", isFuzzy)) ctx.Data["Page"] = pager ctx.HTML(http.StatusOK, tplIssues) diff --git a/templates/shared/search/fuzzy.tmpl b/templates/shared/search/fuzzy.tmpl index 6ddb03c004b0e..5c09d3c15093d 100644 --- a/templates/shared/search/fuzzy.tmpl +++ b/templates/shared/search/fuzzy.tmpl @@ -2,9 +2,9 @@ {{/* IsFuzzy - state of the fuzzy search toggle */}} diff --git a/templates/user/dashboard/issues.tmpl b/templates/user/dashboard/issues.tmpl index 89f23163f75b2..278907e43f470 100644 --- a/templates/user/dashboard/issues.tmpl +++ b/templates/user/dashboard/issues.tmpl @@ -6,29 +6,29 @@