@@ -6,6 +6,7 @@ package bleve
6
6
import (
7
7
"context"
8
8
9
+ "code.gitea.io/gitea/modules/indexer"
9
10
indexer_internal "code.gitea.io/gitea/modules/indexer/internal"
10
11
inner_bleve "code.gitea.io/gitea/modules/indexer/internal/bleve"
11
12
"code.gitea.io/gitea/modules/indexer/issues/internal"
@@ -120,6 +121,10 @@ type Indexer struct {
120
121
indexer_internal.Indexer // do not composite inner_bleve.Indexer directly to avoid exposing too much
121
122
}
122
123
124
+ func (b * Indexer ) SupportedSearchModes () []indexer.SearchMode {
125
+ return indexer .SearchModesExactWordsFuzzy ()
126
+ }
127
+
123
128
// NewIndexer creates a new bleve local indexer
124
129
func NewIndexer (indexDir string ) * Indexer {
125
130
inner := inner_bleve .NewIndexer (indexDir , issueIndexerLatestVersion , generateIssueIndexMapping )
@@ -156,16 +161,21 @@ func (b *Indexer) Delete(_ context.Context, ids ...int64) error {
156
161
func (b * Indexer ) Search (ctx context.Context , options * internal.SearchOptions ) (* internal.SearchResult , error ) {
157
162
var queries []query.Query
158
163
159
- if options .Keyword != "" {
164
+ if options .SearchMode == indexer . SearchModeWords || options . SearchMode == indexer . SearchModeFuzzy {
160
165
fuzziness := 0
161
- if options .IsFuzzyKeyword {
166
+ if options .SearchMode == indexer . SearchModeFuzzy {
162
167
fuzziness = inner_bleve .GuessFuzzinessByKeyword (options .Keyword )
163
168
}
164
-
165
169
queries = append (queries , bleve .NewDisjunctionQuery ([]query.Query {
166
- inner_bleve .MatchPhraseQuery (options .Keyword , "title" , issueIndexerAnalyzer , fuzziness ),
167
- inner_bleve .MatchPhraseQuery (options .Keyword , "content" , issueIndexerAnalyzer , fuzziness ),
168
- inner_bleve .MatchPhraseQuery (options .Keyword , "comments" , issueIndexerAnalyzer , fuzziness ),
170
+ inner_bleve .MatchAndQuery (options .Keyword , "title" , issueIndexerAnalyzer , fuzziness ),
171
+ inner_bleve .MatchAndQuery (options .Keyword , "content" , issueIndexerAnalyzer , fuzziness ),
172
+ inner_bleve .MatchAndQuery (options .Keyword , "comments" , issueIndexerAnalyzer , fuzziness ),
173
+ }... ))
174
+ } else {
175
+ queries = append (queries , bleve .NewDisjunctionQuery ([]query.Query {
176
+ inner_bleve .MatchPhraseQuery (options .Keyword , "title" , issueIndexerAnalyzer , 0 ),
177
+ inner_bleve .MatchPhraseQuery (options .Keyword , "content" , issueIndexerAnalyzer , 0 ),
178
+ inner_bleve .MatchPhraseQuery (options .Keyword , "comments" , issueIndexerAnalyzer , 0 ),
169
179
}... ))
170
180
}
171
181
0 commit comments