Skip to content

Commit 6ff9e69

Browse files
6543silverwind
authored andcommitted
Expose fuzzy search for issues/pulls (#29701)
close #29685 --------- Signed-off-by: 6543 <[email protected]> Co-authored-by: silverwind <[email protected]>
1 parent 9a42833 commit 6ff9e69

File tree

5 files changed

+38
-26
lines changed

5 files changed

+38
-26
lines changed

options/locale/locale_en-US.ini

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@ search = Search...
164164
type_tooltip = Search type
165165
fuzzy = Fuzzy
166166
fuzzy_tooltip = Include results that also match the search term closely
167-
match = Match
168-
match_tooltip = Include only results that match the exact search term
167+
exact = Exact
168+
exact_tooltip = Include only results that match the exact search term
169169
repo_kind = Search repos...
170170
user_kind = Search users...
171171
org_kind = Search orgs...
@@ -179,6 +179,8 @@ branch_kind = Search branches...
179179
commit_kind = Search commits...
180180
runner_kind = Search runners...
181181
no_results = No matching results found.
182+
issue_kind = Search issues...
183+
pull_kind = Search pulls...
182184
keyword_search_unavailable = Searching by keyword is currently not available. Please contact the site administrator.
183185

184186
[aria]

routers/web/user/home.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,8 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
447447
User: ctx.Doer,
448448
}
449449

450+
isFuzzy := ctx.FormBool("fuzzy")
451+
450452
// Search all repositories which
451453
//
452454
// As user:
@@ -546,7 +548,9 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
546548
// USING FINAL STATE OF opts FOR A QUERY.
547549
var issues issues_model.IssueList
548550
{
549-
issueIDs, _, err := issue_indexer.SearchIssues(ctx, issue_indexer.ToSearchOptions(keyword, opts))
551+
issueIDs, _, err := issue_indexer.SearchIssues(ctx, issue_indexer.ToSearchOptions(keyword, opts).Copy(
552+
func(o *issue_indexer.SearchOptions) { o.IsFuzzyKeyword = isFuzzy },
553+
))
550554
if err != nil {
551555
ctx.ServerError("issueIDsFromSearch", err)
552556
return
@@ -567,7 +571,9 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
567571
// -------------------------------
568572
// Fill stats to post to ctx.Data.
569573
// -------------------------------
570-
issueStats, err := getUserIssueStats(ctx, ctxUser, filterMode, issue_indexer.ToSearchOptions(keyword, opts))
574+
issueStats, err := getUserIssueStats(ctx, ctxUser, filterMode, issue_indexer.ToSearchOptions(keyword, opts).Copy(
575+
func(o *issue_indexer.SearchOptions) { o.IsFuzzyKeyword = isFuzzy },
576+
))
571577
if err != nil {
572578
ctx.ServerError("getUserIssueStats", err)
573579
return
@@ -621,6 +627,7 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
621627
ctx.Data["SortType"] = sortType
622628
ctx.Data["IsShowClosed"] = isShowClosed
623629
ctx.Data["SelectLabels"] = selectedLabels
630+
ctx.Data["IsFuzzy"] = isFuzzy
624631

625632
if isShowClosed {
626633
ctx.Data["State"] = "closed"
@@ -634,6 +641,7 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
634641
pager.AddParamString("sort", sortType)
635642
pager.AddParamString("state", fmt.Sprint(ctx.Data["State"]))
636643
pager.AddParamString("labels", selectedLabels)
644+
pager.AddParamString("fuzzy", fmt.Sprintf("%v", isFuzzy))
637645
ctx.Data["Page"] = pager
638646

639647
ctx.HTML(http.StatusOK, tplIssues)

templates/shared/search/fuzzy.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
{{/* IsFuzzy - state of the fuzzy search toggle */}}
33
<div class="ui small dropdown selection {{if .Disabled}} disabled{{end}}" data-tooltip-content="{{ctx.Locale.Tr "search.type_tooltip"}}">
44
<input name="fuzzy" type="hidden"{{if .Disabled}} disabled{{end}} value="{{.IsFuzzy}}">{{svg "octicon-triangle-down" 14 "dropdown icon"}}
5-
<div class="text">{{if .IsFuzzy}}{{ctx.Locale.Tr "search.fuzzy"}}{{else}}{{ctx.Locale.Tr "search.match"}}{{end}}</div>
5+
<div class="text">{{if .IsFuzzy}}{{ctx.Locale.Tr "search.fuzzy"}}{{else}}{{ctx.Locale.Tr "search.exact"}}{{end}}</div>
66
<div class="menu">
77
<div class="item" data-value="true" data-tooltip-content="{{ctx.Locale.Tr "search.fuzzy_tooltip"}}">{{ctx.Locale.Tr "search.fuzzy"}}</div>
8-
<div class="item" data-value="false" data-tooltip-content="{{ctx.Locale.Tr "search.match_tooltip"}}">{{ctx.Locale.Tr "search.match"}}</div>
8+
<div class="item" data-value="false" data-tooltip-content="{{ctx.Locale.Tr "search.exact_tooltip"}}">{{ctx.Locale.Tr "search.exact"}}</div>
99
</div>
1010
</div>

templates/user/dashboard/issues.tmpl

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,29 @@
66
<div class="flex-container">
77
<div class="flex-container-nav">
88
<div class="ui secondary vertical filter menu tw-bg-transparent">
9-
<a class="{{if eq .ViewType "your_repositories"}}active{{end}} item" href="?type=your_repositories&sort={{$.SortType}}&state={{.State}}&q={{$.Keyword}}">
9+
<a class="{{if eq .ViewType "your_repositories"}}active{{end}} item" href="?type=your_repositories&sort={{$.SortType}}&state={{.State}}&q={{$.Keyword}}&fuzzy={{.IsFuzzy}}">
1010
{{ctx.Locale.Tr "home.issues.in_your_repos"}}
1111
<strong>{{CountFmt .IssueStats.YourRepositoriesCount}}</strong>
1212
</a>
13-
<a class="{{if eq .ViewType "assigned"}}active{{end}} item" href="?type=assigned&sort={{$.SortType}}&state={{.State}}&q={{$.Keyword}}">
13+
<a class="{{if eq .ViewType "assigned"}}active{{end}} item" href="?type=assigned&sort={{$.SortType}}&state={{.State}}&q={{$.Keyword}}&fuzzy={{.IsFuzzy}}">
1414
{{ctx.Locale.Tr "repo.issues.filter_type.assigned_to_you"}}
1515
<strong>{{CountFmt .IssueStats.AssignCount}}</strong>
1616
</a>
17-
<a class="{{if eq .ViewType "created_by"}}active{{end}} item" href="?type=created_by&sort={{$.SortType}}&state={{.State}}&q={{$.Keyword}}">
17+
<a class="{{if eq .ViewType "created_by"}}active{{end}} item" href="?type=created_by&sort={{$.SortType}}&state={{.State}}&q={{$.Keyword}}&fuzzy={{.IsFuzzy}}">
1818
{{ctx.Locale.Tr "repo.issues.filter_type.created_by_you"}}
1919
<strong>{{CountFmt .IssueStats.CreateCount}}</strong>
2020
</a>
2121
{{if .PageIsPulls}}
22-
<a class="{{if eq .ViewType "review_requested"}}active{{end}} item" href="?type=review_requested&sort={{$.SortType}}&state={{.State}}&q={{$.Keyword}}">
22+
<a class="{{if eq .ViewType "review_requested"}}active{{end}} item" href="?type=review_requested&sort={{$.SortType}}&state={{.State}}&q={{$.Keyword}}&fuzzy={{.IsFuzzy}}">
2323
{{ctx.Locale.Tr "repo.issues.filter_type.review_requested"}}
2424
<strong>{{CountFmt .IssueStats.ReviewRequestedCount}}</strong>
2525
</a>
26-
<a class="{{if eq .ViewType "reviewed_by"}}active{{end}} item" href="?type=reviewed_by&sort={{$.SortType}}&state={{.State}}&q={{$.Keyword}}">
26+
<a class="{{if eq .ViewType "reviewed_by"}}active{{end}} item" href="?type=reviewed_by&sort={{$.SortType}}&state={{.State}}&q={{$.Keyword}}&fuzzy={{.IsFuzzy}}">
2727
{{ctx.Locale.Tr "repo.issues.filter_type.reviewed_by_you"}}
2828
<strong>{{CountFmt .IssueStats.ReviewedCount}}</strong>
2929
</a>
3030
{{end}}
31-
<a class="{{if eq .ViewType "mentioned"}}active{{end}} item" href="?type=mentioned&sort={{$.SortType}}&state={{.State}}&q={{$.Keyword}}">
31+
<a class="{{if eq .ViewType "mentioned"}}active{{end}} item" href="?type=mentioned&sort={{$.SortType}}&state={{.State}}&q={{$.Keyword}}&fuzzy={{.IsFuzzy}}">
3232
{{ctx.Locale.Tr "repo.issues.filter_type.mentioning_you"}}
3333
<strong>{{CountFmt .IssueStats.MentionCount}}</strong>
3434
</a>
@@ -37,11 +37,11 @@
3737
<div class="flex-container-main content">
3838
<div class="list-header">
3939
<div class="small-menu-items ui compact tiny menu list-header-toggle">
40-
<a class="item{{if not .IsShowClosed}} active{{end}}" href="?type={{$.ViewType}}&sort={{$.SortType}}&state=open&q={{$.Keyword}}">
40+
<a class="item{{if not .IsShowClosed}} active{{end}}" href="?type={{$.ViewType}}&sort={{$.SortType}}&state=open&q={{$.Keyword}}&fuzzy={{.IsFuzzy}}">
4141
{{svg "octicon-issue-opened" 16 "tw-mr-2"}}
4242
{{ctx.Locale.PrettyNumber .IssueStats.OpenCount}}&nbsp;{{ctx.Locale.Tr "repo.issues.open_title"}}
4343
</a>
44-
<a class="item{{if .IsShowClosed}} active{{end}}" href="?type={{$.ViewType}}&sort={{$.SortType}}&state=closed&q={{$.Keyword}}">
44+
<a class="item{{if .IsShowClosed}} active{{end}}" href="?type={{$.ViewType}}&sort={{$.SortType}}&state=closed&q={{$.Keyword}}&fuzzy={{.IsFuzzy}}">
4545
{{svg "octicon-issue-closed" 16 "tw-mr-2"}}
4646
{{ctx.Locale.PrettyNumber .IssueStats.ClosedCount}}&nbsp;{{ctx.Locale.Tr "repo.issues.closed_title"}}
4747
</a>
@@ -51,9 +51,11 @@
5151
<input type="hidden" name="type" value="{{$.ViewType}}">
5252
<input type="hidden" name="sort" value="{{$.SortType}}">
5353
<input type="hidden" name="state" value="{{$.State}}">
54-
{{template "shared/search/input" dict "Value" $.Keyword}}
55-
<button id="issue-list-quick-goto" class="ui small icon button tw-hidden" data-tooltip-content="{{ctx.Locale.Tr "explore.go_to"}}">{{svg "octicon-hash"}}</button>
56-
{{template "shared/search/button"}}
54+
{{if .PageIsPulls}}
55+
{{template "shared/search/combo_fuzzy" dict "Value" $.Keyword "IsFuzzy" $.IsFuzzy "Placeholder" (ctx.Locale.Tr "search.pull_kind") "Tooltip" (ctx.Locale.Tr "explorer.go")}}
56+
{{else}}
57+
{{template "shared/search/combo_fuzzy" dict "Value" $.Keyword "IsFuzzy" $.IsFuzzy "Placeholder" (ctx.Locale.Tr "search.issue_kind") "Tooltip" (ctx.Locale.Tr "explorer.go")}}
58+
{{end}}
5759
</div>
5860
</form>
5961
<!-- Sort -->
@@ -63,14 +65,14 @@
6365
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
6466
</span>
6567
<div class="menu">
66-
<a class="{{if eq .SortType "recentupdate"}}active {{end}}item" href="?type={{$.ViewType}}&sort=recentupdate&state={{$.State}}&q={{$.Keyword}}">{{ctx.Locale.Tr "repo.issues.filter_sort.recentupdate"}}</a>
67-
<a class="{{if eq .SortType "leastupdate"}}active {{end}}item" href="?type={{$.ViewType}}&sort=leastupdate&state={{$.State}}&q={{$.Keyword}}">{{ctx.Locale.Tr "repo.issues.filter_sort.leastupdate"}}</a>
68-
<a class="{{if or (eq .SortType "latest") (not .SortType)}}active {{end}}item" href="?type={{$.ViewType}}&sort=latest&state={{$.State}}&q={{$.Keyword}}">{{ctx.Locale.Tr "repo.issues.filter_sort.latest"}}</a>
69-
<a class="{{if eq .SortType "oldest"}}active {{end}}item" href="?type={{$.ViewType}}&sort=oldest&state={{$.State}}&q={{$.Keyword}}">{{ctx.Locale.Tr "repo.issues.filter_sort.oldest"}}</a>
70-
<a class="{{if eq .SortType "mostcomment"}}active {{end}}item" href="?type={{$.ViewType}}&sort=mostcomment&state={{$.State}}&q={{$.Keyword}}">{{ctx.Locale.Tr "repo.issues.filter_sort.mostcomment"}}</a>
71-
<a class="{{if eq .SortType "leastcomment"}}active {{end}}item" href="?type={{$.ViewType}}&sort=leastcomment&state={{$.State}}&q={{$.Keyword}}">{{ctx.Locale.Tr "repo.issues.filter_sort.leastcomment"}}</a>
72-
<a class="{{if eq .SortType "nearduedate"}}active {{end}}item" href="?type={{$.ViewType}}&sort=nearduedate&state={{$.State}}&q={{$.Keyword}}">{{ctx.Locale.Tr "repo.issues.filter_sort.nearduedate"}}</a>
73-
<a class="{{if eq .SortType "farduedate"}}active {{end}}item" href="?type={{$.ViewType}}&sort=farduedate&state={{$.State}}&q={{$.Keyword}}">{{ctx.Locale.Tr "repo.issues.filter_sort.farduedate"}}</a>
68+
<a class="{{if eq .SortType "recentupdate"}}active {{end}}item" href="?type={{$.ViewType}}&sort=recentupdate&state={{$.State}}&q={{$.Keyword}}&fuzzy={{.IsFuzzy}}">{{ctx.Locale.Tr "repo.issues.filter_sort.recentupdate"}}</a>
69+
<a class="{{if eq .SortType "leastupdate"}}active {{end}}item" href="?type={{$.ViewType}}&sort=leastupdate&state={{$.State}}&q={{$.Keyword}}&fuzzy={{.IsFuzzy}}">{{ctx.Locale.Tr "repo.issues.filter_sort.leastupdate"}}</a>
70+
<a class="{{if or (eq .SortType "latest") (not .SortType)}}active {{end}}item" href="?type={{$.ViewType}}&sort=latest&state={{$.State}}&q={{$.Keyword}}&fuzzy={{.IsFuzzy}}">{{ctx.Locale.Tr "repo.issues.filter_sort.latest"}}</a>
71+
<a class="{{if eq .SortType "oldest"}}active {{end}}item" href="?type={{$.ViewType}}&sort=oldest&state={{$.State}}&q={{$.Keyword}}&fuzzy={{.IsFuzzy}}">{{ctx.Locale.Tr "repo.issues.filter_sort.oldest"}}</a>
72+
<a class="{{if eq .SortType "mostcomment"}}active {{end}}item" href="?type={{$.ViewType}}&sort=mostcomment&state={{$.State}}&q={{$.Keyword}}&fuzzy={{.IsFuzzy}}">{{ctx.Locale.Tr "repo.issues.filter_sort.mostcomment"}}</a>
73+
<a class="{{if eq .SortType "leastcomment"}}active {{end}}item" href="?type={{$.ViewType}}&sort=leastcomment&state={{$.State}}&q={{$.Keyword}}&fuzzy={{.IsFuzzy}}">{{ctx.Locale.Tr "repo.issues.filter_sort.leastcomment"}}</a>
74+
<a class="{{if eq .SortType "nearduedate"}}active {{end}}item" href="?type={{$.ViewType}}&sort=nearduedate&state={{$.State}}&q={{$.Keyword}}&fuzzy={{.IsFuzzy}}">{{ctx.Locale.Tr "repo.issues.filter_sort.nearduedate"}}</a>
75+
<a class="{{if eq .SortType "farduedate"}}active {{end}}item" href="?type={{$.ViewType}}&sort=farduedate&state={{$.State}}&q={{$.Keyword}}&fuzzy={{.IsFuzzy}}">{{ctx.Locale.Tr "repo.issues.filter_sort.farduedate"}}</a>
7476
</div>
7577
</div>
7678
</div>

web_src/css/form.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ textarea,
4040

4141
/* fix fomantic small dropdown having inconsistent padding with input */
4242
.ui.small.selection.dropdown {
43-
padding: .67857143em 3.2em .67857143em 1em;
43+
padding: .67857143em 1.6em .67857143em 1em;
4444
}
4545

4646
input:hover,

0 commit comments

Comments
 (0)