feat: support streaming response for search results (#5630)

Co-authored-by: manx98 <1323517022@qq.com>
This commit is contained in:
Ramires Viana
2025-12-28 17:57:25 -03:00
committed by GitHub
parent f89975603e
commit 20bfd131c6
10 changed files with 183 additions and 39 deletions

View File

@@ -1,6 +1,7 @@
package search
import (
"context"
"os"
"path"
"path/filepath"
@@ -18,13 +19,17 @@ type searchOptions struct {
}
// Search searches for a query in a fs.
func Search(fs afero.Fs, scope, query string, checker rules.Checker, found func(path string, f os.FileInfo) error) error {
func Search(ctx context.Context,
fs afero.Fs, scope, query string, checker rules.Checker, found func(path string, f os.FileInfo) error) error {
search := parseSearch(query)
scope = filepath.ToSlash(filepath.Clean(scope))
scope = path.Join("/", scope)
return afero.Walk(fs, scope, func(fPath string, f os.FileInfo, _ error) error {
if ctx.Err() != nil {
return context.Cause(ctx)
}
fPath = filepath.ToSlash(filepath.Clean(fPath))
fPath = path.Join("/", fPath)
relativePath := strings.TrimPrefix(fPath, scope)