search-tools

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Search Tool Hierarchy

代码搜索工具层级体系

When searching code, use this decision tree:
在搜索代码时,请遵循以下决策树选择合适工具:

Decision Tree

决策树

Need CONCEPTUAL/SEMANTIC search?
  (how does X work, find patterns, understand architecture)
  → Use LEANN (/leann-search) - embedding-based semantic search
  → PreToolUse hook auto-redirects semantic Grep queries

Need to understand code STRUCTURE?
  (find function calls, class usages, refactor patterns)
  → Use AST-grep (/ast-grep-find)

Need to find TEXT in code?
  → Use Morph (/morph-search) - 20x faster
  → If no Morph API key: fall back to Grep tool

Simple one-off search?
  → Use built-in Grep tool directly
是否需要概念/语义搜索?
 (例如:X的工作原理是什么、查找模式、理解架构)
  → 使用LEANN (/leann-search) - 基于嵌入的语义搜索
  → PreToolUse钩子会自动重定向语义Grep查询

是否需要理解代码结构?
 (例如:查找函数调用、类的用法、重构模式)
  → 使用AST-grep (/ast-grep-find)

是否需要在代码中查找文本?
  → 使用Morph (/morph-search) - 速度快20倍
  → 若无Morph API密钥:回退到Grep工具

简单的一次性搜索?
  → 直接使用内置Grep工具

Tool Comparison

工具对比

ToolBest ForRequires
LEANNSemantic search: "how does caching work", "error handling patterns", conceptual queriesIndex built
AST-grepStructural patterns: "find all calls to
foo()
", refactoring, find usages by type
MCP server
MorphFast text search: "find files mentioning error", grep across codebaseAPI key
GrepLiteral patterns, class/function names, regexNothing (built-in)
工具适用场景所需条件
LEANN语义搜索:例如「缓存如何工作」「错误处理模式」「概念类查询」已构建索引
AST-grep结构模式:例如「查找所有
foo()
的调用」「重构」「按类型查找用法」
MCP服务器
Morph快速文本搜索:例如「查找提及error的文件」「跨代码库grep搜索」API密钥
Grep字面量模式、类/函数名称、正则表达式无(内置工具)

Examples

示例

LEANN (semantic/conceptual):
  • "how does authentication work"
  • "find error handling patterns"
  • "where is rate limiting implemented"
AST-grep (structural):
  • "Find all functions that return a Promise"
  • "Find all React components using useState"
  • "Refactor all imports of X to Y"
Morph (text search):
  • "Find all files mentioning 'authentication'"
  • "Search for TODO comments"
Grep (literal):
  • class ProviderAdapter
  • def __init__
  • Regex patterns
LEANN(语义/概念类):
  • 「认证机制如何工作」
  • 「查找错误处理模式」
  • 「限流功能在哪里实现」
AST-grep(结构类):
  • 「查找所有返回Promise的函数」
  • 「查找所有使用useState的React组件」
  • 「将所有X的导入重构为Y」
Morph(文本搜索类):
  • 「查找所有提及'authentication'的文件」
  • 「搜索TODO注释」
Grep(字面量类):
  • class ProviderAdapter
  • def __init__
  • 正则表达式模式

LEANN Commands

LEANN 命令

bash
undefined
bash
undefined

Search with semantic query

执行语义查询搜索

leann search opc-dev "how does blackboard communication work" --top-k 5
leann search opc-dev "how does blackboard communication work" --top-k 5

List available indexes

列出可用索引

leann list
leann list

Rebuild index (when code changes)

重建索引(代码变更时使用)

leann build opc-dev --docs dir1 dir2 --no-recompute --no-compact --force
undefined
leann build opc-dev --docs dir1 dir2 --no-recompute --no-compact --force
undefined