fix(indexer): index full file paths and real offsets in bleve (#39405)

The bleve path token filter added in
https://github.com/go-gitea/gitea/pull/32210 never generated the full
path of a file, so searching a file by its path (e.g. `potato/ham`)
found nothing. It also gave the path tokens made-up offsets instead of
their position in the path.

The filter is replaced by a tokenizer that emits the raw path suffixes
starting at each segment and word (`potato/ham.md`, `ham.md`). Paths
below the root now match too, as do names containing `-` or spaces and
dotfiles. An exact file name also ranks above files inside a directory
with the same name.

---------

Co-authored-by: silverwind <me@silverwind.io>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
Rafail Giavrimis
2026-09-24 07:57:42 +00:00
committed by GitHub
co-authored by silverwind wxiaoguang
parent 8b46a956d8
commit 72243bead7
7 changed files with 66 additions and 191 deletions
+5 -1
View File
@@ -24,7 +24,7 @@ func TestBleveIndexerTokenFilter(t *testing.T) {
require.NoError(t, err)
batch := inner_bleve.NewFlushingBatch(indexer.inner.Indexer, maxBatchSize)
batch.Index("2", &RepoIndexerData{RepoID: 2, Content: "mDNS.port2=12345", UpdatedAt: time.Now()})
batch.Index("2", &RepoIndexerData{RepoID: 2, Filename: ".sub-dir/.sub-filename", Content: "mDNS.port2=12345", UpdatedAt: time.Now()})
batch.Flush()
testCases := []struct {
@@ -36,6 +36,10 @@ func TestBleveIndexerTokenFilter(t *testing.T) {
{keyword: "mdns", expectedIDs: []int64{2}},
{keyword: "port", expectedIDs: []int64{2}},
{keyword: "port2", expectedIDs: []int64{2}},
{keyword: ".sub-dir", expectedIDs: []int64{2}},
{keyword: "sub-file", expectedIDs: []int64{2}}, // prefix matching? not sure whether this behavior is wanted
{keyword: "filename", expectedIDs: []int64{2}},
{keyword: "name", expectedIDs: []int64{}},
}
for _, testCase := range testCases {