@@ -11,6 +11,7 @@ import (
11
11
12
12
"code.gitea.io/gitea/models/db"
13
13
"code.gitea.io/gitea/models/unittest"
14
+ indexer_module "code.gitea.io/gitea/modules/indexer"
14
15
"code.gitea.io/gitea/modules/indexer/code/bleve"
15
16
"code.gitea.io/gitea/modules/indexer/code/elasticsearch"
16
17
"code.gitea.io/gitea/modules/indexer/code/internal"
@@ -39,10 +40,11 @@ func testIndexer(name string, t *testing.T, indexer internal.Indexer) {
39
40
assert .NoError (t , setupRepositoryIndexes (t .Context (), indexer ))
40
41
41
42
keywords := []struct {
42
- RepoIDs []int64
43
- Keyword string
44
- Langs int
45
- Results []codeSearchResult
43
+ RepoIDs []int64
44
+ Keyword string
45
+ Langs int
46
+ SearchMode indexer_module.SearchModeType
47
+ Results []codeSearchResult
46
48
}{
47
49
// Search for an exact match on the contents of a file
48
50
// This scenario yields a single result (the file README.md on the repo '1')
@@ -183,17 +185,18 @@ func testIndexer(name string, t *testing.T, indexer internal.Indexer) {
183
185
},
184
186
// Search for matches on the contents of files regardless of case.
185
187
{
186
- RepoIDs : nil ,
187
- Keyword : "dESCRIPTION" ,
188
- Langs : 1 ,
188
+ RepoIDs : nil ,
189
+ Keyword : "dESCRIPTION" ,
190
+ Langs : 1 ,
191
+ SearchMode : indexer_module .SearchModeFuzzy ,
189
192
Results : []codeSearchResult {
190
193
{
191
194
Filename : "README.md" ,
192
195
Content : "# repo1\n \n Description for repo1" ,
193
196
},
194
197
},
195
198
},
196
- // Search for an exact match on the filename within the repo '62' (case insenstive ).
199
+ // Search for an exact match on the filename within the repo '62' (case-insensitive ).
197
200
// This scenario yields a single result (the file avocado.md on the repo '62')
198
201
{
199
202
RepoIDs : []int64 {62 },
@@ -206,7 +209,7 @@ func testIndexer(name string, t *testing.T, indexer internal.Indexer) {
206
209
},
207
210
},
208
211
},
209
- // Search for matches on the contents of files when the criteria is a expression.
212
+ // Search for matches on the contents of files when the criteria are an expression.
210
213
{
211
214
RepoIDs : []int64 {62 },
212
215
Keyword : "console.log" ,
@@ -218,7 +221,7 @@ func testIndexer(name string, t *testing.T, indexer internal.Indexer) {
218
221
},
219
222
},
220
223
},
221
- // Search for matches on the contents of files when the criteria is part of a expression.
224
+ // Search for matches on the contents of files when the criteria are parts of an expression.
222
225
{
223
226
RepoIDs : []int64 {62 },
224
227
Keyword : "log" ,
@@ -235,16 +238,16 @@ func testIndexer(name string, t *testing.T, indexer internal.Indexer) {
235
238
for _ , kw := range keywords {
236
239
t .Run (kw .Keyword , func (t * testing.T ) {
237
240
total , res , langs , err := indexer .Search (t .Context (), & internal.SearchOptions {
238
- RepoIDs : kw .RepoIDs ,
239
- Keyword : kw .Keyword ,
241
+ RepoIDs : kw .RepoIDs ,
242
+ Keyword : kw .Keyword ,
243
+ SearchMode : kw .SearchMode ,
240
244
Paginator : & db.ListOptions {
241
245
Page : 1 ,
242
246
PageSize : 10 ,
243
247
},
244
- IsKeywordFuzzy : true ,
245
248
})
246
- assert .NoError (t , err )
247
- assert .Len (t , langs , kw .Langs )
249
+ require .NoError (t , err )
250
+ require .Len (t , langs , kw .Langs )
248
251
249
252
hits := make ([]codeSearchResult , 0 , len (res ))
250
253
@@ -289,7 +292,7 @@ func TestBleveIndexAndSearch(t *testing.T) {
289
292
_ , err := idx .Init (t .Context ())
290
293
require .NoError (t , err )
291
294
292
- testIndexer ("beleve " , t , idx )
295
+ testIndexer ("bleve " , t , idx )
293
296
}
294
297
295
298
func TestESIndexAndSearch (t * testing.T ) {
0 commit comments