feat: add support to opt-in for fuzzy search (#10378)

The rationale for keeping it behind a flag is due to fuzzy search being computationally intensive #5261
Admins may opt-in by setting the `[indexer].REPO_INDEXER_FUZZY_ENABLED` flag to true.

Closes #10331

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/10378
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
Co-authored-by: Shiny Nematoda <snematoda.751k2@aleeas.com>
Co-committed-by: Shiny Nematoda <snematoda.751k2@aleeas.com>
This commit is contained in:
Shiny Nematoda 2025-12-17 13:51:48 +01:00 committed by Gusted
parent 32429c0b13
commit cdc27b0d62
13 changed files with 175 additions and 52 deletions

View file

@ -23,16 +23,17 @@ var Indexer = struct {
IssueIndexerName string
StartupTimeout time.Duration
RepoIndexerEnabled bool
RepoIndexerRepoTypes []string
RepoType string
RepoPath string
RepoConnStr string
RepoIndexerName string
MaxIndexerFileSize int64
IncludePatterns []Glob
ExcludePatterns []Glob
ExcludeVendored bool
RepoIndexerEnabled bool
RepoIndexerRepoTypes []string
RepoIndexerEnableFuzzy bool
RepoType string
RepoPath string
RepoConnStr string
RepoIndexerName string
MaxIndexerFileSize int64
IncludePatterns []Glob
ExcludePatterns []Glob
ExcludeVendored bool
}{
IssueType: "bleve",
IssuePath: "indexers/issues.bleve",
@ -40,14 +41,15 @@ var Indexer = struct {
IssueConnAuth: "",
IssueIndexerName: "gitea_issues",
RepoIndexerEnabled: false,
RepoIndexerRepoTypes: []string{"sources", "forks", "mirrors", "templates"},
RepoType: "bleve",
RepoPath: "indexers/repos.bleve",
RepoConnStr: "",
RepoIndexerName: "gitea_codes",
MaxIndexerFileSize: 1024 * 1024,
ExcludeVendored: true,
RepoIndexerEnabled: false,
RepoIndexerRepoTypes: []string{"sources", "forks", "mirrors", "templates"},
RepoIndexerEnableFuzzy: false,
RepoType: "bleve",
RepoPath: "indexers/repos.bleve",
RepoConnStr: "",
RepoIndexerName: "gitea_codes",
MaxIndexerFileSize: 1024 * 1024,
ExcludeVendored: true,
}
type Glob struct {
@ -87,6 +89,7 @@ func loadIndexerFrom(rootCfg ConfigProvider) {
Indexer.RepoIndexerEnabled = sec.Key("REPO_INDEXER_ENABLED").MustBool(false)
Indexer.RepoIndexerRepoTypes = strings.Split(sec.Key("REPO_INDEXER_REPO_TYPES").MustString("sources,forks,mirrors,templates"), ",")
Indexer.RepoIndexerEnableFuzzy = sec.Key("REPO_INDEXER_FUZZY_ENABLED").MustBool(false)
Indexer.RepoType = sec.Key("REPO_INDEXER_TYPE").MustString("bleve")
Indexer.RepoPath = filepath.ToSlash(sec.Key("REPO_INDEXER_PATH").MustString(filepath.ToSlash(filepath.Join(AppDataPath, "indexers/repos.bleve"))))
if !filepath.IsAbs(Indexer.RepoPath) {