@@ -16,6 +16,7 @@ import (
1616 "code.gitea.io/gitea/modules/charset"
1717 "code.gitea.io/gitea/modules/git"
1818 "code.gitea.io/gitea/modules/gitrepo"
19+ "code.gitea.io/gitea/modules/indexer"
1920 "code.gitea.io/gitea/modules/indexer/code/internal"
2021 indexer_internal "code.gitea.io/gitea/modules/indexer/internal"
2122 inner_elasticsearch "code.gitea.io/gitea/modules/indexer/internal/elasticsearch"
@@ -24,7 +25,6 @@ import (
2425 "code.gitea.io/gitea/modules/setting"
2526 "code.gitea.io/gitea/modules/timeutil"
2627 "code.gitea.io/gitea/modules/typesniffer"
27- "code.gitea.io/gitea/modules/util"
2828
2929 "github.com/go-enry/go-enry/v2"
3030 "github.com/olivere/elastic/v7"
@@ -46,6 +46,10 @@ type Indexer struct {
4646 indexer_internal.Indexer // do not composite inner_elasticsearch.Indexer directly to avoid exposing too much
4747}
4848
49+ func (b * Indexer ) SupportedSearchModes () []indexer.SearchMode {
50+ return indexer .SearchModesExactWords ()
51+ }
52+
4953// NewIndexer creates a new elasticsearch indexer
5054func NewIndexer (url , indexerName string ) * Indexer {
5155 inner := inner_elasticsearch .NewIndexer (url , indexerName , esRepoIndexerLatestVersion , defaultMapping )
@@ -361,15 +365,10 @@ func extractAggs(searchResult *elastic.SearchResult) []*internal.SearchResultLan
361365// Search searches for codes and language stats by given conditions.
362366func (b * Indexer ) Search (ctx context.Context , opts * internal.SearchOptions ) (int64 , []* internal.SearchResult , []* internal.SearchResultLanguages , error ) {
363367 var contentQuery elastic.Query
364- keywordAsPhrase , isPhrase := internal .ParseKeywordAsPhrase (opts .Keyword )
365- if isPhrase {
366- contentQuery = elastic .NewMatchPhraseQuery ("content" , keywordAsPhrase )
368+ if opts .SearchMode == indexer .SearchModeExact {
369+ contentQuery = elastic .NewMatchPhraseQuery ("content" , opts .Keyword )
367370 } else {
368- // TODO: this is the old logic, but not really using "fuzziness"
369- // * IsKeywordFuzzy=true: "best_fields"
370- // * IsKeywordFuzzy=false: "phrase_prefix"
371- contentQuery = elastic .NewMultiMatchQuery ("content" , opts .Keyword ).
372- Type (util .Iif (opts .IsKeywordFuzzy , esMultiMatchTypeBestFields , esMultiMatchTypePhrasePrefix ))
371+ contentQuery = elastic .NewMultiMatchQuery ("content" , opts .Keyword ).Type (esMultiMatchTypeBestFields ).Operator ("and" )
373372 }
374373 kwQuery := elastic .NewBoolQuery ().Should (
375374 contentQuery ,
0 commit comments