diff --git a/Makefile b/Makefile index 51577a48f0da2..4f3ec034496b9 100644 --- a/Makefile +++ b/Makefile @@ -792,7 +792,7 @@ security-check: go run $(GOVULNCHECK_PACKAGE) ./... $(EXECUTABLE): $(GO_SOURCES) $(TAGS_PREREQ) - CGO_CFLAGS="$(CGO_CFLAGS)" $(GO) build $(GOFLAGS) $(EXTRA_GOFLAGS) -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)' -o $@ + CGO_CFLAGS="$(CGO_CFLAGS)" $(GO) build $(GOFLAGS) $(EXTRA_GOFLAGS) -tags '$(TAGS)' -ldflags '$(LDFLAGS)' -o $@ .PHONY: release release: frontend generate release-windows release-linux release-darwin release-freebsd release-copy release-compress vendor release-sources release-docs release-check diff --git a/modules/indexer/internal/bleve/query.go b/modules/indexer/internal/bleve/query.go index 21422b281c498..c5399fe47f980 100644 --- a/modules/indexer/internal/bleve/query.go +++ b/modules/indexer/internal/bleve/query.go @@ -28,6 +28,14 @@ func MatchPhraseQuery(matchPhrase, field, analyzer string, fuzziness int) *query return q } +// FuzzyQuery generates a fuzzy query for the given phrase, field, and fuzziness +func FuzzyQuery(matchPhrase, field string, fuzziness int) *query.FuzzyQuery { + q := bleve.NewFuzzyQuery(matchPhrase) + q.FieldVal = field + q.Fuzziness = fuzziness + return q +} + // BoolFieldQuery generates a bool field query for the given value and field func BoolFieldQuery(value bool, field string) *query.BoolFieldQuery { q := bleve.NewBoolFieldQuery(value) diff --git a/modules/indexer/internal/bleve/util.go b/modules/indexer/internal/bleve/util.go index a2265f86e6b35..67f9f838ae956 100644 --- a/modules/indexer/internal/bleve/util.go +++ b/modules/indexer/internal/bleve/util.go @@ -57,5 +57,5 @@ func GuessFuzzinessByKeyword(s string) int { return 0 } } - return min(2, len(s)/4) + return 1 } diff --git a/modules/indexer/issues/bleve/bleve.go b/modules/indexer/issues/bleve/bleve.go index 7ef370e89c5d2..b1368465335a9 100644 --- a/modules/indexer/issues/bleve/bleve.go +++ b/modules/indexer/issues/bleve/bleve.go @@ -157,12 +157,16 @@ func (b *Indexer) Search(ctx context.Context, options *internal.SearchOptions) ( if options.Keyword != "" { fuzziness := 0 + var titleQuery query.Query if options.IsFuzzyKeyword { fuzziness = inner_bleve.GuessFuzzinessByKeyword(options.Keyword) + titleQuery = inner_bleve.FuzzyQuery(options.Keyword, "title", fuzziness) + } else { + titleQuery = inner_bleve.MatchPhraseQuery(options.Keyword, "title", issueIndexerAnalyzer, fuzziness) } queries = append(queries, bleve.NewDisjunctionQuery([]query.Query{ - inner_bleve.MatchPhraseQuery(options.Keyword, "title", issueIndexerAnalyzer, fuzziness), + titleQuery, inner_bleve.MatchPhraseQuery(options.Keyword, "content", issueIndexerAnalyzer, fuzziness), inner_bleve.MatchPhraseQuery(options.Keyword, "comments", issueIndexerAnalyzer, fuzziness), }...)) diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go index 7c4e3e36f3caa..537474cbd4202 100644 --- a/routers/web/repo/issue.go +++ b/routers/web/repo/issue.go @@ -2677,6 +2677,7 @@ func SearchIssues(ctx *context.Context) { MilestoneIDs: includedMilestones, ProjectID: projectID, SortBy: issue_indexer.SortByCreatedDesc, + IsFuzzyKeyword: true, } if since != 0 {