This folder demonstrates practical use cases for ck (semantic grep) with real code examples.
-
Index the examples first (required for semantic/lexical/hybrid search):
ck --index examples/
-
Try the quick demo:
./examples/quick_demo.sh
-
Try the examples below using the demo files in this folder.
full_section_demo.py- Python code with classes, functions, error handlingweb_server.rs- Rust web server with authentication, database connections, error handlingapi_client.js- JavaScript API client with HTTP requests, retry logic, authentication
fixtures/- Simple demo text files (demo1.txt to demo10.txt)wiki_articles/- Wikipedia articles on various topics (AI, science, technology, etc.)
Classic grep-style pattern matching:
# Basic text search ck "error" examples/ # Case-insensitive search ck -i "database" examples/ # Whole word matching ck -w "class" examples/ # Fixed string (no regex) ck -F "def __init__" examples/ # With line numbers and context ck -n -C 2 "error" examples/Understands meaning, not just text matches:
# Find error handling patterns (try/catch, exception handling, etc.) ck --sem "error handling" examples/ # Find database-related code ck --sem "database connection" text_samples/ # Find authentication logic ck --sem "user authentication" examples/ # Limit results and show scores ck --sem --limit 5 --scores "data processing" examples/ # Higher precision filtering ck --sem --threshold 0.8 "function" examples/Better than regex for phrase matching:
# Full-text search with relevance ranking ck --lex "user authentication" examples/ # Multi-word phrases ck --lex "error handling patterns" examples/Combines regex precision with semantic understanding:
# Most comprehensive search ck --hybrid "async function" examples/ # Find specific patterns with semantic context ck --hybrid "database" --limit 10 examples/ # Show relevance scores ck --hybrid "error" --scores examples/Get complete code blocks instead of just matching lines:
# Return entire functions/classes containing matches ck --sem --full-section "error handling" examples/ # Works with all search modes ck --hybrid --full-section "database" examples/Machine-readable results for scripts and tools:
# JSON output for integration ck --json --sem "error handling" examples/ # Pipe to jq for processing ck --json --sem "database" examples/ | jq '.preview'# Show surrounding lines ck -A 3 -B 1 "class" examples/ # 3 after, 1 before ck -C 2 "def" examples/ # 2 lines of context # File listing modes ck -l "error" examples/ # List files with matches ck -L "nonexistent" examples/ # List files without matches# Find potential security issues ck --sem "sql injection" examples/ ck --sem "password storage" examples/ # Find error handling patterns ck --sem "exception handling" examples/# Understand new codebase ck --sem "main entry point" examples/ ck --sem "configuration setup" examples/ # Find similar implementations ck --sem "data validation" examples/# Find deprecated patterns ck --hybrid "old api" examples/ # Locate specific implementations ck --sem "async operations" examples/# Find examples of usage ck --sem "example usage" examples/ # Locate API patterns ck --sem "rest api" examples/- Index once, search many times: Use
ck --indexbefore semantic searches - Use appropriate search modes:
- Regex for exact patterns
- Semantic for concept-based searches
- Hybrid for comprehensive results
- Adjust thresholds: Lower values = more results, higher = more precise
- Use --limit: Control result count for large codebases
Run these commands to see ck in action:
# Index the examples ck --index examples/ # Compare different search modes on the same query echo "=== Regex ===" ck "error" examples/ echo "=== Semantic ===" ck --sem "error" examples/ echo "=== Hybrid ===" ck --hybrid "error" examples/Notice how each mode finds different but relevant results!