全文搜索工具

Tamsaek是一个本地文件搜索引擎,具备全文搜索、正则表达式搜索和元数据过滤功能,可作为MCP服务器或CLI工具使用。

  • by Indosaram
  • Rust
  • 本地部署
  • 更新于
在 GitHub 查看 Indosaram/tamsaek

使用说明

坦萨克

具有全文功能的本地文件搜索引擎。建于 坦提维 为了快速搜索。既可作为 MCP服务器 以及一个独立的 CLI工具.

特性

  • 全文检索:由Tantivy提供短语、布尔运算符和特定字段查询
  • 正则表达式搜索:使用正则表达式查找模式(术语级)
  • 元数据筛选:按文件扩展名、源类型筛选
  • 增量索引:添加文档而不重建索引
  • 零外部依赖:不需要单独的数据库或搜索服务器
  • 共享索引:CLI和MCP服务器共享同一索引——索引一次,从任何地方搜索
  • 符合MCP标准:正确的错误处理、工具注释

安装

源自源头

git clone https://github.com/Indosaram/tamsaek.git
cd tamsaek
cargo build --release

二进制:

  • target/release/tamsaek-mcp --MCP服务器
  • target/release/tamsaek --CLI工具

使用货物

# MCP server
cargo install tamsaek-mcp

# CLI tool
cargo install tamsaek-cli

CLI使用情况

全局选项

选项 描述
-i, --index-path <PATH> 自定义索引路径(默认:操作系统数据目录)
-h, --help 打印帮助
-V, --version 打印版本

tamsaek index --为目录建立索引

递归扫描目录并将文件添加到搜索索引中。

# Index all files in a directory
tamsaek index /path/to/project

# Index only specific extensions
tamsaek index /path/to/project -e rs,toml,md

# Non-recursive indexing (current directory only)
tamsaek index /path/to/project --recursive false
选项 描述
<PATH> 要索引的目录的路径(必需)
-e, --extensions <EXT> 以逗号分隔的要包含的文件扩展名列表(例如。 rs,md,txt)
-r, --recursive 递归索引(默认值: true)

tamsaek search --全文搜索

使用自然语言查询在索引文档中搜索。

tamsaek search "error handling"
tamsaek search "TamsaekIndex" --limit 5
选项 描述
<QUERY> 搜索查询(必填)
-l, --limit <N> 要返回的最大结果(默认值: 10)

输出示例:

Found 4 results for 'TamsaekIndex':
[1] /path/to/lib.rs (Score: 3.42)
  ID: /path/to/lib.rs
  Snippet: use tamsaek_core::{TamsaekIndex, Document};

tamsaek search-regex --正则表达式搜索

使用正则表达式模式搜索文档。Regex在 学期水平 (单个单词),而不是整行。

tamsaek search-regex "tamsaek.*"
tamsaek search-regex "inde[x]" --limit 3
选项 描述
<PATTERN> 要搜索的正则表达式模式(必需)
-l, --limit <N> 要返回的最大结果(默认值: 10)

备注:Tantivy正则表达式匹配单个标记化术语。多单词模式,如 fn.*open 不会跨越令牌边界匹配。使用以下模式 doc.*ment (在一个单词内)。


tamsaek filter --筛选文档

按文件扩展名或源类型筛选索引文档。

# List all .rs files
tamsaek filter --extension rs

# Filter by source
tamsaek filter --source local --limit 20

# Combine filters
tamsaek filter --extension md --source local
选项 描述
-e, --extension <EXT> 要筛选的文件扩展名(例如。 rs)
-s, --source <SOURCE> 要过滤的来源(例如。 local)
-l, --limit <N> 要返回的最大结果(默认值: 10)

tamsaek get-document --检索文档

通过ID(通常是文件路径)从索引中获取特定文档。

# Preview (truncated to 500 chars)
tamsaek get-document "/path/to/file.rs"

# Full content
tamsaek get-document "/path/to/file.rs" --full
选项 描述
<ID> 要检索的文档ID(必需)
--full 显示完整内容,而不是500个字符的预览

tamsaek stats --指数统计

显示有关当前索引的信息。

tamsaek stats

输出示例:

Index Statistics:
  Path: /Users/you/Library/Application Support/tamsaek/index
  Documents: 27

tamsaek remove --删除文档

按ID从索引中删除单个文档。

tamsaek remove "/path/to/old-file.rs"
选项 描述
<ID> 要删除的文档ID(必需)

tamsaek clear --清除索引

移除 全部 索引中的文档。提示确认,除非 --force 使用。

# With confirmation prompt
tamsaek clear

# Skip confirmation
tamsaek clear --force
选项 描述
-f, --force 跳过确认提示

MCP服务器使用情况

使用Claude Desktop进行设置

添加 ~/Library/Application Support/Claude/claude_desktop_config.json:

{
  "mcpServers": {
    "tamsaek": {
      "command": "/path/to/tamsaek-mcp"
    }
  }
}

可用的MCP工具

工具 描述 只读
search 全文搜索 是
search-regex 正则表达式模式搜索 是
filter 按扩展名/来源筛选 是
get-document 按ID检索文档 是
index-directory 索引目录中的文件 否
remove-document 删除文档 否
get-stats 指数统计 是
clear-index 清除所有文档 否(破坏性)

MCP工具示例

搜索:

{
  "query": "rust programming",
  "limit": 20
}

索引目录:

{
  "path": "/path/to/documents",
  "extensions": ["txt", "md", "rs"],
  "recursive": true
}

建筑

tamsaek/
├── crates/
│   ├── tamsaek-core/   # Search engine library (shared)
│   ├── tamsaek-mcp/    # MCP server binary
│   └── tamsaek-cli/    # CLI tool binary

tamsaek-core 提供由MCP服务器和CLI共享的索引和搜索引擎。这意味着他们在 同一指数 --通过CLI索引的文档可以从MCP服务器立即搜索,反之亦然。

配置

索引位置

按平台列出的默认索引目录:

平台 路径
macOS ~/Library/Application Support/tamsaek/index
Linux ~/.local/share/tamsaek/index
窗户 %APPDATA%\tamsaek\index

用覆盖 --index-path 标志:

tamsaek --index-path /custom/path search "query"

发展

# Check compilation
cargo check

# Run tests (includes integration tests for CLI)
cargo test

# Run with logging
RUST_LOG=info cargo run -p tamsaek-mcp

# Build release
cargo build --release

许可证

MIT许可证-请参阅 许可证