mirror of https://github.com/go-gitea/gitea.git
Improve issue & code search (#33860)
Each "indexer" should provide the "search modes" they support by themselves. And we need to remove the "fuzzy" search for code.main
parent
cd10456664
commit
403775e74e
@ -1,30 +0,0 @@
|
|||||||
// Copyright 2025 The Gitea Authors. All rights reserved.
|
|
||||||
// SPDX-License-Identifier: MIT
|
|
||||||
|
|
||||||
package internal
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestParseKeywordAsPhrase(t *testing.T) {
|
|
||||||
cases := []struct {
|
|
||||||
keyword string
|
|
||||||
phrase string
|
|
||||||
isPhrase bool
|
|
||||||
}{
|
|
||||||
{``, "", false},
|
|
||||||
{`a`, "", false},
|
|
||||||
{`"`, "", false},
|
|
||||||
{`"a`, "", false},
|
|
||||||
{`"a"`, "a", true},
|
|
||||||
{`""\"""`, `"\""`, true},
|
|
||||||
}
|
|
||||||
for _, c := range cases {
|
|
||||||
phrase, isPhrase := ParseKeywordAsPhrase(c.keyword)
|
|
||||||
assert.Equal(t, c.phrase, phrase, "keyword=%q", c.keyword)
|
|
||||||
assert.Equal(t, c.isPhrase, isPhrase, "keyword=%q", c.keyword)
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,54 @@
|
|||||||
|
// Copyright 2025 The Gitea Authors. All rights reserved.
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
package indexer
|
||||||
|
|
||||||
|
type SearchModeType string
|
||||||
|
|
||||||
|
const (
|
||||||
|
SearchModeExact SearchModeType = "exact"
|
||||||
|
SearchModeWords SearchModeType = "words"
|
||||||
|
SearchModeFuzzy SearchModeType = "fuzzy"
|
||||||
|
SearchModeRegexp SearchModeType = "regexp"
|
||||||
|
)
|
||||||
|
|
||||||
|
type SearchMode struct {
|
||||||
|
ModeValue SearchModeType
|
||||||
|
TooltipTrKey string
|
||||||
|
TitleTrKey string
|
||||||
|
}
|
||||||
|
|
||||||
|
func SearchModesExactWords() []SearchMode {
|
||||||
|
return []SearchMode{
|
||||||
|
{
|
||||||
|
ModeValue: SearchModeExact,
|
||||||
|
TooltipTrKey: "search.exact_tooltip",
|
||||||
|
TitleTrKey: "search.exact",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ModeValue: SearchModeWords,
|
||||||
|
TooltipTrKey: "search.words_tooltip",
|
||||||
|
TitleTrKey: "search.words",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func SearchModesExactWordsFuzzy() []SearchMode {
|
||||||
|
return append(SearchModesExactWords(), []SearchMode{
|
||||||
|
{
|
||||||
|
ModeValue: SearchModeFuzzy,
|
||||||
|
TooltipTrKey: "search.fuzzy_tooltip",
|
||||||
|
TitleTrKey: "search.fuzzy",
|
||||||
|
},
|
||||||
|
}...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func GitGrepSupportedSearchModes() []SearchMode {
|
||||||
|
return append(SearchModesExactWords(), []SearchMode{
|
||||||
|
{
|
||||||
|
ModeValue: SearchModeRegexp,
|
||||||
|
TooltipTrKey: "search.regexp_tooltip",
|
||||||
|
TitleTrKey: "search.regexp",
|
||||||
|
},
|
||||||
|
}...)
|
||||||
|
}
|
@ -1,8 +1,30 @@
|
|||||||
{{/* Value - value of the search field (for search results page) */}}
|
{{/* Attributes:
|
||||||
{{/* Disabled (optional) - if search field/button has to be disabled */}}
|
* Value - value of the search field (for search results page)
|
||||||
{{/* Placeholder (optional) - placeholder text to be used */}}
|
* Disabled (optional) - if search field/button has to be disabled
|
||||||
{{/* Tooltip (optional) - a tooltip to be displayed on button hover */}}
|
* Placeholder (optional) - placeholder text to be used
|
||||||
|
* Tooltip (optional) - a tooltip to be displayed on button hover
|
||||||
|
* SearchModes - a list of search modes to be displayed in the dropdown
|
||||||
|
* SelectedSearchMode - the currently selected search mode
|
||||||
|
*/}}
|
||||||
<div class="ui small fluid action input">
|
<div class="ui small fluid action input">
|
||||||
{{template "shared/search/input" dict "Value" .Value "Disabled" .Disabled "Placeholder" .Placeholder}}
|
{{template "shared/search/input" dict "Value" .Value "Disabled" .Disabled "Placeholder" .Placeholder}}
|
||||||
|
{{if .SearchModes}}
|
||||||
|
<div class="ui small dropdown selection {{if .Disabled}}disabled{{end}}" data-tooltip-content="{{ctx.Locale.Tr "search.type_tooltip"}}">
|
||||||
|
<div class="text"></div> {{svg "octicon-triangle-down" 14 "dropdown icon"}}
|
||||||
|
<input name="search_mode" type="hidden" value="
|
||||||
|
{{- if .SelectedSearchMode -}}
|
||||||
|
{{- .SelectedSearchMode -}}
|
||||||
|
{{- else -}}
|
||||||
|
{{- $defaultSearchMode := index .SearchModes 0 -}}
|
||||||
|
{{- $defaultSearchMode.ModeValue -}}
|
||||||
|
{{- end -}}
|
||||||
|
">
|
||||||
|
<div class="menu">
|
||||||
|
{{range $mode := .SearchModes}}
|
||||||
|
<div class="item" data-value="{{$mode.ModeValue}}" data-tooltip-content="{{ctx.Locale.Tr $mode.TooltipTrKey}}">{{ctx.Locale.Tr $mode.TitleTrKey}}</div>
|
||||||
|
{{end}}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{{end}}
|
||||||
{{template "shared/search/button" dict "Disabled" .Disabled "Tooltip" .Tooltip}}
|
{{template "shared/search/button" dict "Disabled" .Disabled "Tooltip" .Tooltip}}
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
{{/* Value - value of the search field (for search results page) */}}
|
|
||||||
{{/* Disabled (optional) - if search field/button has to be disabled */}}
|
|
||||||
{{/* Placeholder (optional) - placeholder text to be used */}}
|
|
||||||
{{/* IsFuzzy - state of the fuzzy search toggle */}}
|
|
||||||
{{/* Tooltip (optional) - a tooltip to be displayed on button hover */}}
|
|
||||||
<div class="ui small fluid action input">
|
|
||||||
{{template "shared/search/input" dict "Value" .Value "Disabled" .Disabled "Placeholder" .Placeholder}}
|
|
||||||
{{template "shared/search/fuzzy" dict "Disabled" .Disabled "IsFuzzy" .IsFuzzy}}
|
|
||||||
{{template "shared/search/button" dict "Disabled" .Disabled "Tooltip" .Tooltip}}
|
|
||||||
</div>
|
|
@ -1,10 +0,0 @@
|
|||||||
{{/* Disabled (optional) - if dropdown has to be disabled */}}
|
|
||||||
{{/* IsFuzzy - state of the fuzzy search toggle */}}
|
|
||||||
<div class="ui small dropdown selection {{if .Disabled}} disabled{{end}}" data-tooltip-content="{{ctx.Locale.Tr "search.type_tooltip"}}">
|
|
||||||
<input name="fuzzy" type="hidden"{{if .Disabled}} disabled{{end}} value="{{.IsFuzzy}}">{{svg "octicon-triangle-down" 14 "dropdown icon"}}
|
|
||||||
<div class="text">{{if .IsFuzzy}}{{ctx.Locale.Tr "search.fuzzy"}}{{else}}{{ctx.Locale.Tr "search.exact"}}{{end}}</div>
|
|
||||||
<div class="menu">
|
|
||||||
<div class="item" data-value="true" data-tooltip-content="{{ctx.Locale.Tr "search.fuzzy_tooltip"}}">{{ctx.Locale.Tr "search.fuzzy"}}</div>
|
|
||||||
<div class="item" data-value="false" data-tooltip-content="{{ctx.Locale.Tr "search.exact_tooltip"}}">{{ctx.Locale.Tr "search.exact"}}</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
Loading…
Reference in New Issue