feat: filepath filter for code search (#6143)
Added support for searching content in a specific directory or file. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/6143 Reviewed-by: Gusted <gusted@noreply.codeberg.org> Reviewed-by: 0ko <0ko@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:
parent
bb88e1daf8
commit
ee214cb886
19 changed files with 342 additions and 61 deletions
|
@ -0,0 +1,59 @@
|
|||
// Copyright 2024 The Forgejo Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package hierarchy
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestIndexerBleveHierarchyTokenizer(t *testing.T) {
|
||||
tokenizer := &PathHierarchyTokenizer{}
|
||||
keywords := []struct {
|
||||
Term string
|
||||
Results []string
|
||||
}{
|
||||
{
|
||||
Term: "modules/indexer/code/search.go",
|
||||
Results: []string{
|
||||
"modules",
|
||||
"modules/indexer",
|
||||
"modules/indexer/code",
|
||||
"modules/indexer/code/search.go",
|
||||
},
|
||||
},
|
||||
{
|
||||
Term: "/tmp/forgejo/",
|
||||
Results: []string{
|
||||
"tmp",
|
||||
"tmp/forgejo",
|
||||
},
|
||||
},
|
||||
{
|
||||
Term: "a/b/c/d/e/f/g/h/i/j",
|
||||
Results: []string{
|
||||
"a",
|
||||
"a/b",
|
||||
"a/b/c",
|
||||
"a/b/c/d",
|
||||
"a/b/c/d/e",
|
||||
"a/b/c/d/e/f",
|
||||
"a/b/c/d/e/f/g",
|
||||
"a/b/c/d/e/f/g/h",
|
||||
"a/b/c/d/e/f/g/h/i",
|
||||
"a/b/c/d/e/f/g/h/i/j",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, kw := range keywords {
|
||||
tokens := tokenizer.Tokenize([]byte(kw.Term))
|
||||
assert.Len(t, tokens, len(kw.Results))
|
||||
for i, token := range tokens {
|
||||
assert.Equal(t, i+1, token.Position)
|
||||
assert.Equal(t, kw.Results[i], string(token.Term))
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue