Skip to content

Commit 076e99f

Browse files
committed
Merge remote-tracking branch 'upstream/main'
2 parents 0c9d222 + 3c6fc25 commit 076e99f

File tree

55 files changed

+540
-201
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+540
-201
lines changed

.devcontainer/devcontainer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
},
99
"ghcr.io/devcontainers/features/git-lfs:1.1.0": {},
1010
"ghcr.io/devcontainers-contrib/features/poetry:2": {},
11-
"ghcr.io/devcontainers/features/python:1": {}
11+
"ghcr.io/devcontainers/features/python:1": {
12+
"version": "3.12"
13+
}
1214
},
1315
"customizations": {
1416
"vscode": {

docs/content/administration/config-cheat-sheet.en-us.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,7 @@ Default templates for project boards:
832832
## Issue and pull request attachments (`attachment`)
833833

834834
- `ENABLED`: **true**: Whether issue and pull request attachments are enabled.
835-
- `ALLOWED_TYPES`: **.csv,.docx,.fodg,.fodp,.fods,.fodt,.gif,.gz,.jpeg,.jpg,.log,.md,.mov,.mp4,.odf,.odg,.odp,.ods,.odt,.patch,.pdf,.png,.pptx,.svg,.tgz,.txt,.webm,.xls,.xlsx,.zip**: Comma-separated list of allowed file extensions (`.zip`), mime types (`text/plain`) or wildcard type (`image/*`, `audio/*`, `video/*`). Empty value or `*/*` allows all types.
835+
- `ALLOWED_TYPES`: **.cpuprofile,.csv,.dmp,.docx,.fodg,.fodp,.fods,.fodt,.gif,.gz,.jpeg,.jpg,.json,.jsonc,.log,.md,.mov,.mp4,.odf,.odg,.odp,.ods,.odt,.patch,.pdf,.png,.pptx,.svg,.tgz,.txt,.webm,.xls,.xlsx,.zip**: Comma-separated list of allowed file extensions (`.zip`), mime types (`text/plain`) or wildcard type (`image/*`, `audio/*`, `video/*`). Empty value or `*/*` allows all types.
836836
- `MAX_SIZE`: **2048**: Maximum size (MB).
837837
- `MAX_FILES`: **5**: Maximum number of attachments that can be uploaded at once.
838838
- `STORAGE_TYPE`: **local**: Storage type for attachments, `local` for local disk or `minio` for s3 compatible object storage service, default is `local` or other name defined with `[storage.xxx]`

docs/content/administration/config-cheat-sheet.zh-cn.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@ Gitea 创建以下非唯一队列:
782782
## 工单和合并请求的附件 (`attachment`)
783783

784784
- `ENABLED`: **true**: 是否允许用户上传附件。
785-
- `ALLOWED_TYPES`: **.csv,.docx,.fodg,.fodp,.fods,.fodt,.gif,.gz,.jpeg,.jpg,.log,.md,.mov,.mp4,.odf,.odg,.odp,.ods,.odt,.patch,.pdf,.png,.pptx,.svg,.tgz,.txt,.webm,.xls,.xlsx,.zip**: 允许的文件扩展名(`.zip`)、mime 类型(`text/plain`)或通配符类型(`image/*``audio/*``video/*`)的逗号分隔列表。空值或 `*/*` 允许所有类型。
785+
- `ALLOWED_TYPES`: **.cpuprofile,.csv,.dmp,.docx,.fodg,.fodp,.fods,.fodt,.gif,.gz,.jpeg,.jpg,.json,.jsonc,.log,.md,.mov,.mp4,.odf,.odg,.odp,.ods,.odt,.patch,.pdf,.png,.pptx,.svg,.tgz,.txt,.webm,.xls,.xlsx,.zip**: 允许的文件扩展名(`.zip`)、mime 类型(`text/plain`)或通配符类型(`image/*``audio/*``video/*`)的逗号分隔列表。空值或 `*/*` 允许所有类型。
786786
- `MAX_SIZE`: **2048**: 附件的最大限制(MB)。
787787
- `MAX_FILES`: **5**: 一次最多上传的附件数量。
788788
- `STORAGE_TYPE`: **local**: 附件的存储类型,`local` 表示本地磁盘,`minio` 表示兼容 S3 的对象存储服务,如果未设置将使用默认值 `local` 或其他在 `[storage.xxx]` 中定义的名称。

modules/indexer/code/bleve/bleve.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -233,21 +233,21 @@ func (b *Indexer) Delete(_ context.Context, repoID int64) error {
233233

234234
// Search searches for files in the specified repo.
235235
// Returns the matching file-paths
236-
func (b *Indexer) Search(ctx context.Context, repoIDs []int64, language, keyword string, page, pageSize int, isMatch bool) (int64, []*internal.SearchResult, []*internal.SearchResultLanguages, error) {
236+
func (b *Indexer) Search(ctx context.Context, repoIDs []int64, language, keyword string, page, pageSize int, isFuzzy bool) (int64, []*internal.SearchResult, []*internal.SearchResultLanguages, error) {
237237
var (
238238
indexerQuery query.Query
239239
keywordQuery query.Query
240240
)
241241

242-
if isMatch {
243-
prefixQuery := bleve.NewPrefixQuery(keyword)
244-
prefixQuery.FieldVal = "Content"
245-
keywordQuery = prefixQuery
246-
} else {
242+
if isFuzzy {
247243
phraseQuery := bleve.NewMatchPhraseQuery(keyword)
248244
phraseQuery.FieldVal = "Content"
249245
phraseQuery.Analyzer = repoIndexerAnalyzer
250246
keywordQuery = phraseQuery
247+
} else {
248+
prefixQuery := bleve.NewPrefixQuery(keyword)
249+
prefixQuery.FieldVal = "Content"
250+
keywordQuery = prefixQuery
251251
}
252252

253253
if len(repoIDs) > 0 {

modules/indexer/code/elasticsearch/elasticsearch.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,10 +281,10 @@ func extractAggs(searchResult *elastic.SearchResult) []*internal.SearchResultLan
281281
}
282282

283283
// Search searches for codes and language stats by given conditions.
284-
func (b *Indexer) Search(ctx context.Context, repoIDs []int64, language, keyword string, page, pageSize int, isMatch bool) (int64, []*internal.SearchResult, []*internal.SearchResultLanguages, error) {
285-
searchType := esMultiMatchTypeBestFields
286-
if isMatch {
287-
searchType = esMultiMatchTypePhrasePrefix
284+
func (b *Indexer) Search(ctx context.Context, repoIDs []int64, language, keyword string, page, pageSize int, isFuzzy bool) (int64, []*internal.SearchResult, []*internal.SearchResultLanguages, error) {
285+
searchType := esMultiMatchTypePhrasePrefix
286+
if isFuzzy {
287+
searchType = esMultiMatchTypeBestFields
288288
}
289289

290290
kwQuery := elastic.NewMultiMatchQuery(keyword, "content").Type(searchType)

modules/indexer/code/git.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,9 @@ func genesisChanges(ctx context.Context, repo *repo_model.Repository, revision s
9191
return nil, runErr
9292
}
9393

94+
objectFormat := git.ObjectFormatFromName(repo.ObjectFormatName)
95+
9496
var err error
95-
objectFormat, err := git.GetObjectFormatOfRepo(ctx, repo.RepoPath())
96-
if err != nil {
97-
return nil, err
98-
}
9997
changes.Updates, err = parseGitLsTreeOutput(objectFormat, stdout)
10098
return &changes, err
10199
}
@@ -174,10 +172,8 @@ func nonGenesisChanges(ctx context.Context, repo *repo_model.Repository, revisio
174172
return nil, err
175173
}
176174

177-
objectFormat, err := git.GetObjectFormatOfRepo(ctx, repo.RepoPath())
178-
if err != nil {
179-
return nil, err
180-
}
175+
objectFormat := git.ObjectFormatFromName(repo.ObjectFormatName)
176+
181177
changes.Updates, err = parseGitLsTreeOutput(objectFormat, lsTreeStdout)
182178
return &changes, err
183179
}

modules/indexer/code/indexer_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func testIndexer(name string, t *testing.T, indexer internal.Indexer) {
7070

7171
for _, kw := range keywords {
7272
t.Run(kw.Keyword, func(t *testing.T) {
73-
total, res, langs, err := indexer.Search(context.TODO(), kw.RepoIDs, "", kw.Keyword, 1, 10, false)
73+
total, res, langs, err := indexer.Search(context.TODO(), kw.RepoIDs, "", kw.Keyword, 1, 10, true)
7474
assert.NoError(t, err)
7575
assert.Len(t, kw.IDs, int(total))
7676
assert.Len(t, langs, kw.Langs)

modules/indexer/code/internal/indexer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type Indexer interface {
1616
internal.Indexer
1717
Index(ctx context.Context, repo *repo_model.Repository, sha string, changes *RepoChanges) error
1818
Delete(ctx context.Context, repoID int64) error
19-
Search(ctx context.Context, repoIDs []int64, language, keyword string, page, pageSize int, isMatch bool) (int64, []*SearchResult, []*SearchResultLanguages, error)
19+
Search(ctx context.Context, repoIDs []int64, language, keyword string, page, pageSize int, isFuzzy bool) (int64, []*SearchResult, []*SearchResultLanguages, error)
2020
}
2121

2222
// NewDummyIndexer returns a dummy indexer
@@ -38,6 +38,6 @@ func (d *dummyIndexer) Delete(ctx context.Context, repoID int64) error {
3838
return fmt.Errorf("indexer is not ready")
3939
}
4040

41-
func (d *dummyIndexer) Search(ctx context.Context, repoIDs []int64, language, keyword string, page, pageSize int, isMatch bool) (int64, []*SearchResult, []*SearchResultLanguages, error) {
41+
func (d *dummyIndexer) Search(ctx context.Context, repoIDs []int64, language, keyword string, page, pageSize int, isFuzzy bool) (int64, []*SearchResult, []*SearchResultLanguages, error) {
4242
return 0, nil, nil, fmt.Errorf("indexer is not ready")
4343
}

modules/indexer/code/search.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,13 @@ func searchResult(result *internal.SearchResult, startIndex, endIndex int) (*Res
124124
}
125125

126126
// PerformSearch perform a search on a repository
127-
func PerformSearch(ctx context.Context, repoIDs []int64, language, keyword string, page, pageSize int, isMatch bool) (int, []*Result, []*internal.SearchResultLanguages, error) {
127+
// if isFuzzy is true set the Damerau-Levenshtein distance from 0 to 2
128+
func PerformSearch(ctx context.Context, repoIDs []int64, language, keyword string, page, pageSize int, isFuzzy bool) (int, []*Result, []*internal.SearchResultLanguages, error) {
128129
if len(keyword) == 0 {
129130
return 0, nil, nil, nil
130131
}
131132

132-
total, results, resultLanguages, err := (*globalIndexer.Load()).Search(ctx, repoIDs, language, keyword, page, pageSize, isMatch)
133+
total, results, resultLanguages, err := (*globalIndexer.Load()).Search(ctx, repoIDs, language, keyword, page, pageSize, isFuzzy)
133134
if err != nil {
134135
return 0, nil, nil, err
135136
}

modules/indexer/internal/bleve/query.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ func MatchPhraseQuery(matchPhrase, field, analyzer string) *query.MatchPhraseQue
2525
return q
2626
}
2727

28+
// PrefixQuery generates a match prefix query for the given prefix and field
29+
func PrefixQuery(matchPrefix, field string) *query.PrefixQuery {
30+
q := bleve.NewPrefixQuery(matchPrefix)
31+
q.FieldVal = field
32+
return q
33+
}
34+
2835
// BoolFieldQuery generates a bool field query for the given value and field
2936
func BoolFieldQuery(value bool, field string) *query.BoolFieldQuery {
3037
q := bleve.NewBoolFieldQuery(value)

0 commit comments

Comments
 (0)