aboutsummaryrefslogtreecommitdiffstats
path: root/routers/common/codesearch.go
blob: a14af126e55bce64648e4e92aeef7e5cc3329bde (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Copyright 2024 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

package common

import (
	"code.gitea.io/gitea/modules/setting"
	"code.gitea.io/gitea/services/context"
)

func PrepareCodeSearch(ctx *context.Context) (ret struct {
	Keyword  string
	Language string
	IsFuzzy  bool
},
) {
	ret.Language = ctx.FormTrim("l")
	ret.Keyword = ctx.FormTrim("q")

	fuzzyDefault := setting.Indexer.RepoIndexerEnabled
	fuzzyAllow := true
	if setting.Indexer.RepoType == "bleve" && setting.Indexer.TypeBleveMaxFuzzniess == 0 {
		fuzzyDefault = false
		fuzzyAllow = false
	}
	isFuzzy := ctx.FormOptionalBool("fuzzy").ValueOrDefault(fuzzyDefault)
	if isFuzzy && !fuzzyAllow {
		ctx.Flash.Info("Fuzzy search is disabled by default due to performance reasons")
		isFuzzy = false
	}

	ctx.Data["IsBleveFuzzyDisabled"] = true
	ctx.Data["Keyword"] = ret.Keyword
	ctx.Data["Language"] = ret.Language
	ctx.Data["IsFuzzy"] = isFuzzy

	ctx.Data["IsRepoIndexerEnabled"] = setting.Indexer.RepoIndexerEnabled
	return ret
}