Skip to content

Commit e87e418

Browse files
committed
simplify code per comments
1 parent dcb58f0 commit e87e418

File tree

6 files changed

+18
-29
lines changed

6 files changed

+18
-29
lines changed

modules/indexer/code/bleve/bleve.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,8 @@ func (b *Indexer) Search(ctx context.Context, opts *internal.SearchOptions) (int
267267
pathQuery.FieldVal = "Filename"
268268
pathQuery.SetBoost(10)
269269

270-
if opts.IsKeywordLiteral {
270+
if strings.HasPrefix(opts.Keyword, "\"") && strings.HasSuffix(opts.Keyword, "\"") {
271+
opts.Keyword = strings.Trim(opts.Keyword, "\"")
271272
q := bleve.NewMatchPhraseQuery(opts.Keyword)
272273
q.FieldVal = "Content"
273274
contentQuery = q

modules/indexer/code/internal/indexer.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ type SearchOptions struct {
2525
Keyword string
2626
Language string
2727

28-
IsKeywordFuzzy bool
29-
IsKeywordLiteral bool
28+
IsKeywordFuzzy bool
3029

3130
db.Paginator
3231
}

routers/common/codesearch.go

+3-11
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,14 @@
44
package common
55

66
import (
7-
"strings"
8-
97
"code.gitea.io/gitea/modules/setting"
108
"code.gitea.io/gitea/services/context"
119
)
1210

1311
func PrepareCodeSearch(ctx *context.Context) (ret struct {
14-
Keyword string
15-
Language string
16-
IsFuzzy bool
17-
IsLiteral bool
12+
Keyword string
13+
Language string
14+
IsFuzzy bool
1815
},
1916
) {
2017
ret.Language = ctx.FormTrim("l")
@@ -38,10 +35,5 @@ func PrepareCodeSearch(ctx *context.Context) (ret struct {
3835
ctx.Data["IsFuzzy"] = isFuzzy
3936

4037
ctx.Data["IsRepoIndexerEnabled"] = setting.Indexer.RepoIndexerEnabled
41-
42-
if strings.HasPrefix(ret.Keyword, "\"") && strings.HasSuffix(ret.Keyword, "\"") {
43-
ret.Keyword = strings.Trim(ret.Keyword, "\"")
44-
ret.IsLiteral = true
45-
}
4638
return ret
4739
}

routers/web/explore/code.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,10 @@ func Code(ctx *context.Context) {
7272

7373
if (len(repoIDs) > 0) || isAdmin {
7474
total, searchResults, searchResultLanguages, err = code_indexer.PerformSearch(ctx, &code_indexer.SearchOptions{
75-
RepoIDs: repoIDs,
76-
Keyword: prepareSearch.Keyword,
77-
IsKeywordFuzzy: prepareSearch.IsFuzzy,
78-
IsKeywordLiteral: prepareSearch.IsLiteral,
79-
Language: prepareSearch.Language,
75+
RepoIDs: repoIDs,
76+
Keyword: prepareSearch.Keyword,
77+
IsKeywordFuzzy: prepareSearch.IsFuzzy,
78+
Language: prepareSearch.Language,
8079
Paginator: &db.ListOptions{
8180
Page: page,
8281
PageSize: setting.UI.RepoSearchPagingNum,

routers/web/repo/search.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,10 @@ func Search(ctx *context.Context) {
4848
if setting.Indexer.RepoIndexerEnabled {
4949
var err error
5050
total, searchResults, searchResultLanguages, err = code_indexer.PerformSearch(ctx, &code_indexer.SearchOptions{
51-
RepoIDs: []int64{ctx.Repo.Repository.ID},
52-
Keyword: prepareSearch.Keyword,
53-
IsKeywordFuzzy: prepareSearch.IsFuzzy,
54-
IsKeywordLiteral: prepareSearch.IsLiteral,
55-
Language: prepareSearch.Language,
51+
RepoIDs: []int64{ctx.Repo.Repository.ID},
52+
Keyword: prepareSearch.Keyword,
53+
IsKeywordFuzzy: prepareSearch.IsFuzzy,
54+
Language: prepareSearch.Language,
5655
Paginator: &db.ListOptions{
5756
Page: page,
5857
PageSize: setting.UI.RepoSearchPagingNum,

routers/web/user/code.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,10 @@ func CodeSearch(ctx *context.Context) {
6868

6969
if len(repoIDs) > 0 {
7070
total, searchResults, searchResultLanguages, err = code_indexer.PerformSearch(ctx, &code_indexer.SearchOptions{
71-
RepoIDs: repoIDs,
72-
Keyword: prepareSearch.Keyword,
73-
IsKeywordFuzzy: prepareSearch.IsFuzzy,
74-
IsKeywordLiteral: prepareSearch.IsLiteral,
75-
Language: prepareSearch.Language,
71+
RepoIDs: repoIDs,
72+
Keyword: prepareSearch.Keyword,
73+
IsKeywordFuzzy: prepareSearch.IsFuzzy,
74+
Language: prepareSearch.Language,
7675
Paginator: &db.ListOptions{
7776
Page: page,
7877
PageSize: setting.UI.RepoSearchPagingNum,

0 commit comments

Comments
 (0)