From 0d2007e4c6c4a0b10a61c763cc2ab78cce7ce4e9 Mon Sep 17 00:00:00 2001 From: charles7668 Date: Fri, 21 Mar 2025 14:10:25 +0800 Subject: [PATCH 1/2] Fix file name could not be searched if the file was not a text file when using the Bleve indexer. --- modules/indexer/code/bleve/bleve.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/indexer/code/bleve/bleve.go b/modules/indexer/code/bleve/bleve.go index e1a381f992c82..b541805efca0f 100644 --- a/modules/indexer/code/bleve/bleve.go +++ b/modules/indexer/code/bleve/bleve.go @@ -191,7 +191,7 @@ func (b *Indexer) addUpdate(ctx context.Context, batchWriter git.WriteCloserErro return err } else if !typesniffer.DetectContentType(fileContents).IsText() { // FIXME: UTF-16 files will probably fail here - return nil + fileContents = make([]byte, 0) } if _, err = batchReader.Discard(1); err != nil { From 6cefb0e2c00e7900b3772279881e28b514472dcf Mon Sep 17 00:00:00 2001 From: charles <30816317+charles7668@users.noreply.github.com> Date: Fri, 21 Mar 2025 19:16:25 +0800 Subject: [PATCH 2/2] Update modules/indexer/code/bleve/bleve.go Co-authored-by: wxiaoguang --- modules/indexer/code/bleve/bleve.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/indexer/code/bleve/bleve.go b/modules/indexer/code/bleve/bleve.go index b541805efca0f..130ee78a4b90d 100644 --- a/modules/indexer/code/bleve/bleve.go +++ b/modules/indexer/code/bleve/bleve.go @@ -191,7 +191,8 @@ func (b *Indexer) addUpdate(ctx context.Context, batchWriter git.WriteCloserErro return err } else if !typesniffer.DetectContentType(fileContents).IsText() { // FIXME: UTF-16 files will probably fail here - fileContents = make([]byte, 0) + // Even if the file is not recognized as a "text file", we could still put its name into the indexers to make the filename become searchable, while leave the content to empty. + fileContents = nil } if _, err = batchReader.Discard(1); err != nil {