Files
fn_registry/functions/infra/vault_search.md
T
egutierrez e3c8979e8d chore: auto-commit (95 archivos)
- cmd/fn/doctor.go
- cmd/fn/main.go
- cpp/apps/primitives_gallery/playground/tables/CMakeLists.txt
- cpp/apps/primitives_gallery/playground/tables/data_table.cpp
- cpp/apps/primitives_gallery/playground/tables/data_table_logic.cpp
- cpp/apps/primitives_gallery/playground/tables/data_table_logic.h
- cpp/apps/primitives_gallery/playground/tables/self_test.cpp
- cpp/apps/primitives_gallery/playground/tables/tql.cpp
- cpp/apps/primitives_gallery/playground/tables/viz.cpp
- cpp/apps/primitives_gallery/playground/tables/viz.h
- ...

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-13 00:50:34 +02:00

2.3 KiB

name, kind, lang, domain, version, purity, signature, description, tags, uses_functions, uses_types, returns, returns_optional, error_type, imports, params, output, tested, tests, test_file_path, file_path
name kind lang domain version purity signature description tags uses_functions uses_types returns returns_optional error_type imports params output tested tests test_file_path file_path
vault_search function go infra 1.0.0 impure func VaultSearch(vaultPath, query string, limit int) ([]VaultSearchHit, error) Busca en vault_index.db de un vault usando FTS5 sobre files_fts. Si el query rompe el parser FTS5, hace fallback a LIKE sobre rel_path. Retorna hits con snippet de contexto.
vault
search
fts5
sqlite
infra
vault_index_open_go_infra
vault_file_go_infra
false error_go_core
database/sql
fmt
path/filepath
strings
name desc
vaultPath ruta absoluta al directorio raiz del vault (puede ser symlink)
name desc
query termino o frase de busqueda; se escapa automaticamente para FTS5 salvo que ya incluya operadores booleanos o prefijos de columna
name desc
limit maximo de resultados; si es <= 0 se usa 50
slice de VaultSearchHit ordenado por rank FTS5 (o mtime DESC en fallback LIKE); slice vacio si no hay resultados true
FTS match devuelve hit con snippet
query sin resultados retorna slice vacio
limit se respeta
query FTS invalida activa fallback LIKE
limit cero usa 50 por defecto
functions/infra/vault_search_test.go functions/infra/vault_search.go

Ejemplo

hits, err := infra.VaultSearch("/home/lucas/vaults/turismo_spain", "hoteles", 20)
if err != nil {
    log.Fatal(err)
}
for _, h := range hits {
    fmt.Printf("[%s] %s  %s\n", h.VaultName, h.RelPath, h.Snippet)
}

Notas

VaultSearchHit es un struct local definido en este archivo (no en vault_file.go) porque combina campos de files + metadatos de contexto de busqueda (Snippet, VaultPath, VaultName).

FTS5 safety: el helper safeFTSQuery envuelve la query en comillas dobles cuando no contiene operadores booleanos ni prefijos de columna. Esto evita errores del parser en tokens como foo:bar: o hello-world.

Fallback LIKE: si el MATCH falla con un error de sintaxis FTS5, se ejecuta WHERE rel_path LIKE '%' || query || '%'. Los hits del fallback tienen Snippet="".

VaultName: se deriva del filepath.Base(filepath.EvalSymlinks(vaultPath)). Si EvalSymlinks falla (e.g. symlink roto), usa filepath.Base(vaultPath).