jojo/routers/common/search.go
Christoph Mewes 023a894677 chore: fix typos throughout the codebase (#10753)
This PR fixes a number of typos throughout the entire repository. Running https://github.com/crate-ci/typos and then changing all occurrences that I naively deemed "safe enough".

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/10753
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
Co-authored-by: Christoph Mewes <christoph@kubermatic.com>
Co-committed-by: Christoph Mewes <christoph@kubermatic.com>
2026-01-26 22:57:33 +01:00

55 lines
1.5 KiB
Go

// Copyright 2025 The Forgejo Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package common
import (
code_indexer "forgejo.org/modules/indexer/code"
"forgejo.org/modules/setting"
"forgejo.org/services/context"
)
type CodeSearchOptions struct {
Language, Keyword, Path string
}
// Parses the common code search options from the context
// This functions takes care of the following ctx.Data fields
// - Keyword
// - Language
// - CodeSearchPath
func InitCodeSearchOptions(ctx *context.Context) (opts CodeSearchOptions) {
opts.Language = ctx.FormTrim("l")
opts.Keyword = ctx.FormTrim("q")
opts.Path = ctx.FormTrim("path")
ctx.Data["Keyword"] = opts.Keyword
ctx.Data["Language"] = opts.Language
ctx.Data["CodeSearchPath"] = opts.Path
return opts
}
// Returns the indexer mode to be used by the code indexer
// Also sets the ctx.Data fields "CodeSearchMode" and "CodeSearchOptions"
//
// NOTE:
// This is separate from `InitCodeSearchOptions`
// since this is specific the indexer and only used
// where git-grep is not available.
func CodeSearchIndexerMode(ctx *context.Context) (mode code_indexer.SearchMode) {
mode = code_indexer.SearchModeExact
if m := ctx.FormTrim("mode"); m == "union" {
mode = code_indexer.SearchModeUnion
} else if m == "fuzzy" || ctx.FormBool("fuzzy") {
if setting.Indexer.RepoIndexerEnableFuzzy {
mode = code_indexer.SearchModeFuzzy
} else {
mode = code_indexer.SearchModeUnion
}
}
ctx.Data["CodeSearchOptions"] = code_indexer.CodeSearchOptions
ctx.Data["CodeSearchMode"] = mode.String()
return mode
}