fsearch README

The project's README from github.com/noahdunnagan/fsearch. As one markdown file: README.md.

FSearch

Whole-disk file search for macOS: names in about 0.1 ms, typo-tolerant, plus indexed search inside files. A CLI with a small daemon, or a Rust crate.

cargo build --release && ./target/release/fsearch install   # -> ~/.local/bin/fsearch
fsearch fsearch main              # find files by name
fsearch 'ext:rs grep:apply_dir'   # search inside files

Speed

M4 Max, 8.3M files on disk, vs the previous version (76d612f). Same results. Medians.

before now
find a file by name 1.0 ms 0.13 ms 7.7×
typing a whole filename, all keystrokes 23 ms 3.0 ms 7.5×
search inside files 14 ms 2.3 ms 6.2×
slowest 10% inside files (Chromium) 38 ms 2.3 ms 16×
CLI, launch to answer 5.5 ms 3.3 ms 1.7×
first run, fully searchable 101 s 49 s 2.1×
first run, peak memory 1.2 GB 0.9 GB
index on disk (Chromium) 0.32 GB 0.76 GB 2.4× bigger

The index grew because each file carries a filter that lets search skip files without the text.

Queries

fsearch 'readme in:~/Developer'          # inside a folder
fsearch 'type:image size:>5mb mtime:<7d'
fsearch 'ext:rs regex:fn\s+\w+_dir'      # regex inside files
fsearch 'sym:apply_dir'                  # where it's defined

Words are fuzzy, and 5+ letter words forgive one typo (mian.rs finds main.rs). Also 'exact, ^prefix, suffix$ and !exclude. Filters: ext: type: kind: in: size: mtime: re: path: grep: regex: sym: limit:. Content search is smart-case.

Full Disk Access

From a terminal with Full Disk Access it indexes everything. As a login item (fsearch install --login), grant ~/.local/bin/fsearch access in System Settings > Privacy & Security, again after each rebuild. Without access it skips protected folders instead of prompting.

API

JSON lines over ~/Library/Application Support/FSearch/fsearch.sock, or fsearch stdio:

{"q": "fsearch main", "limit": 20}
{"op": "grep", "pattern": "apply_dir", "in": "~/Developer"}

Or link the crate:

let engine = fsearch::Engine::start(fsearch::Options { dir: fsearch::default_dir(&home), home: home.clone(), skip: None })?;
let hits = engine.search(&fsearch::Query::parse("fsearch main", &home)?)?;

An app and the CLI share one index: the first process owns it, the rest follow.

How it works

fsearch (noahdunnagan/fsearch)

Searching Database…

2.1K ·GitHub
这是什么?FSearch 是一款 macOS 全盘文件搜索工具,按名字找任何文件大约 1 毫秒就能出结果,能容忍拼写错误,还能靠索引搜索文件内容。
它是 CLI 工具还是 Rust 库?两者都是:它以 CLI 形式发布,背后带一个小的后台守护进程;同样的功能也可以作为 Rust crate 链接进你自己的项目。
怎么让它跑起来?在已授予完全磁盘访问权限的终端里运行它,让它能爬取整个磁盘;再用 fsearch install --login 把它注册为登录项(可选),实现自动启动。
必须先授予完全磁盘访问权限吗?要获得完整覆盖就必须——FSearch 需要在系统设置里授予完全磁盘访问权限,而且每次重新构建二进制后都要重新授权。
如果不授予完全磁盘访问权限会怎样?它不会弹权限提示来烦你——只是静默跳过它看不到的受保护文件夹,其他一切照常索引。
它在 Linux 上也能跑,还是仅限 macOS?它是专门为 macOS 构建的:靠 getattrlistbulk 和 FSEvents 来爬取和实时更新,权限也走 macOS 系统设置。
我的数据会离开这台机器吗?不会——一切都在本地运行:后台守护进程把磁盘爬一遍并把索引留在本机,内容匹配结果从本地磁盘现读,不会被存到别处或发往任何地方。
和 fff 这类工具相比,fsearch 表现如何?在 50.9 万个文件的测试里,fsearch 按名字查找用时 1.1ms(fff 为 13.8ms),内容搜索用时 5.6ms(fff 为 53ms),全盘索引只占 50MB 内存(fff 光一个文件夹就要 358MB)。
它支持什么查询语法?查询默认模糊匹配(5 个以上字母的单词容忍一个拼写错误),也可以用 'exact、^prefix、suffix$ 和 !exclude,还有 ext:、type:、kind:、in:、size:、mtime:、re:、path:、grep:、regex:、sym: 和 limit: 这些过滤器。
文件变化时它怎么保持最新?启动时用 getattrlistbulk 全盘爬一遍,之后靠监听 FSEvents 保持同步,新增、改名或删除的文件约 0.1 秒内就会出现;重启时只回放变化的部分。
应用和 CLI 能共享同一个搜索索引吗?可以——FSearch 通过 ~/Library/Application Support/FSearch/fsearch.sock 上的 Unix socket(或经 stdio)对外提供 JSON lines,先启动的进程持有索引,其他进程直接跟随。
What are similar projects?ripgrep, memex, meilisearch, fff, leviathan, sonic, tantivy, typesense
Size
3.2 MB
Stars
2.1K
Age
9d
Commits · 90 Days