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
+12
View File
@@ -178,6 +178,18 @@ func testIndexer(name string, t *testing.T, indexer internal.Indexer) {
},
},
},
// Search for a match on the full path of a file within the repo '62'.
{
RepoIDs: []int64{62},
Keyword: "potato/ham",
Langs: 1,
Results: []codeSearchResult{
{
Filename: "potato/ham.md",
Content: "This is not cheese",
},
},
},
// Search for matches on the contents of files within the repo '62'.
// This scenario yields two results (both are based on contents, the first one is an exact match where as the second is a 'fuzzy' one)
{