@@ -16,6 +16,7 @@ import (
16
16
"code.gitea.io/gitea/modules/charset"
17
17
"code.gitea.io/gitea/modules/git"
18
18
"code.gitea.io/gitea/modules/gitrepo"
19
+ "code.gitea.io/gitea/modules/indexer"
19
20
"code.gitea.io/gitea/modules/indexer/code/internal"
20
21
indexer_internal "code.gitea.io/gitea/modules/indexer/internal"
21
22
inner_elasticsearch "code.gitea.io/gitea/modules/indexer/internal/elasticsearch"
@@ -24,7 +25,6 @@ import (
24
25
"code.gitea.io/gitea/modules/setting"
25
26
"code.gitea.io/gitea/modules/timeutil"
26
27
"code.gitea.io/gitea/modules/typesniffer"
27
- "code.gitea.io/gitea/modules/util"
28
28
29
29
"github.com/go-enry/go-enry/v2"
30
30
"github.com/olivere/elastic/v7"
@@ -46,6 +46,10 @@ type Indexer struct {
46
46
indexer_internal.Indexer // do not composite inner_elasticsearch.Indexer directly to avoid exposing too much
47
47
}
48
48
49
+ func (b * Indexer ) SupportedSearchModes () []indexer.SearchMode {
50
+ return indexer .SearchModesExactWords ()
51
+ }
52
+
49
53
// NewIndexer creates a new elasticsearch indexer
50
54
func NewIndexer (url , indexerName string ) * Indexer {
51
55
inner := inner_elasticsearch .NewIndexer (url , indexerName , esRepoIndexerLatestVersion , defaultMapping )
@@ -361,15 +365,10 @@ func extractAggs(searchResult *elastic.SearchResult) []*internal.SearchResultLan
361
365
// Search searches for codes and language stats by given conditions.
362
366
func (b * Indexer ) Search (ctx context.Context , opts * internal.SearchOptions ) (int64 , []* internal.SearchResult , []* internal.SearchResultLanguages , error ) {
363
367
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 )
367
370
} 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" )
373
372
}
374
373
kwQuery := elastic .NewBoolQuery ().Should (
375
374
contentQuery ,
0 commit comments