Query Syntax
sqry uses a structured boolean query language. Queries are composed of field predicates combined with logical operators. This page covers the full syntax and when to use each of the two query commands.
Basic Structure
A query is one or more predicates of the form field:value, combined with boolean operators:
field:value OPERATOR field:value
Examples:
sqry query "kind:function"
sqry query "kind:function AND async:true"
sqry query "lang:rust AND (kind:function OR kind:method)"
sqry provides two commands for running queries:
sqry query— searches the pre-built index. Fast (4ms with a warm cache), supports all relation fields (callers:,callees:,imports:,exports:). Requires runningsqry index .first.sqry search— parses files on demand, no index required. Slower, does not support relation queries. Useful for exploring unfamiliar codebases without setup.
Operators
| Operator | Meaning | Example |
|---|---|---|
: | Exact match or segment match (case-insensitive) | name:login matches login, MyClass.login |
~= | Regex match (PCRE syntax, anchored to value) | name~=/^test_/ |
> | Greater than (numeric fields) | line:>100 |
< | Less than (numeric fields) | line:<50 |
>= | Greater than or equal | line:>=10 |
<= | Less than or equal | line:<=200 |
AND | Both predicates must match | kind:function AND async:true |
OR | Either predicate must match | kind:class OR kind:struct |
NOT | Predicate must not match | NOT name~=/test/ |
( ) | Group predicates to control precedence | (kind:function OR kind:method) AND lang:rust |
Regex patterns use PCRE syntax and are wrapped in / delimiters: name~=/pattern/. Common patterns:
name~=/^test_/— starts withtest_name~=/Handler$/— ends withHandlername~=/auth/— containsauth
Field Overview
Fields are organized into three categories:
| Category | Fields | Description |
|---|---|---|
| Symbol fields | kind:, name:, lang:, path:, visibility:, async:, returns: | Attributes of individual symbols |
| Relation fields | callers:, callees:, imports:, exports:, impl: | Cross-symbol relationships (index required) |
| Scope fields | parent:, scope.type:, scope.name:, scope.ancestor: | Containment and nesting |
See Field Reference for the complete list with all accepted values.
Worked Examples
All functions:
sqry query "kind:function"
# Returns every function symbol in the indexed codebase.
All async functions:
sqry query "kind:function AND async:true"
# Returns only functions marked async — no false positives from comments or strings.
Functions whose name starts with test_:
sqry query "name~=/^test_/"
# Regex match anchored to the start of the symbol name.
Everything that calls authenticate:
sqry query "callers:authenticate"
# Cross-file call graph traversal — returns the exact list of callers.
All Serialize implementations:
sqry query "impl:Serialize"
# Finds every struct/enum that implements the Serialize trait.
Public Rust symbols:
sqry query "lang:rust AND visibility:public"
# Filters by both language and visibility simultaneously.
Classes in the models directory:
sqry query "kind:class AND path:src/models/**"
# Glob pattern on the file path.
Non-test functions and methods:
sqry query "(kind:function OR kind:method) AND NOT name~=/test/"
# Grouping with OR, combined with a negated regex filter.
sqry query vs sqry search
sqry query | sqry search | |
|---|---|---|
| Index required | Yes (sqry index . first) | No |
| Speed | 4ms (warm cache) | Parses files on demand |
| Relation queries | Yes (callers:, callees:, imports:, exports:) | No |
| Best for | Regular development, CI checks, relation traversal | First-time exploration, one-off lookups |
Use sqry query when you are working in a project regularly and need instant, precise results — especially for any query involving callers, callees, imports, or exports. The one-time indexing cost is recovered within the first few queries.
Use sqry search when you are exploring a codebase for the first time and do not want to build an index, or when you need results that reflect the very latest unsaved file state.
Query Variables
Use --var to inject values into queries at runtime. Reference variables with $name:
sqry query "callers:$fn AND lang:$lang" --var fn=authenticate --var lang=rust
Multiple variables can be passed. This is useful for scripting and batch workflows where the same query template runs against different targets:
for fn in authenticate authorize logout; do
sqry query "callers:$fn" --var fn=$fn --json
done
Fuzzy Search
Fuzzy matching finds symbols even when the query contains typos or partial names. It requires an index.
# Enable fuzzy matching
sqry query "authentcate" --fuzzy
# Control similarity threshold (0.0–1.0, default 0.6)
sqry query "authentcate" --fuzzy --fuzzy-threshold 0.8
# Choose algorithm
sqry query "authentcate" --fuzzy --fuzzy-algorithm levenshtein
Algorithms
| Algorithm | Behavior | Best for |
|---|---|---|
jaro-winkler (default) | Favors strings that share a common prefix | Symbol names with shared conventions |
levenshtein | Counts minimum edits (insert, delete, replace) | Short names, exact typo correction |
Additional options
| Flag | Default | Description |
|---|---|---|
--fuzzy-max-candidates | 1000 | Max candidates evaluated (higher = slower, more thorough) |
--json-stream | — | Newline-delimited JSON output for streaming |
--fuzzy-fields | — | Enable typo correction for field names (e.g., knd:function → kind:function) |
--fuzzy-field-distance | 2 | Max edit distance for field name correction |
Output Formats
By default, sqry prints human-readable tabular output. Use flags to switch formats:
# JSON (full symbol details)
sqry query "kind:function" --json
# CSV with headers
sqry query "kind:function" --csv --headers
# TSV for Unix pipelines
sqry query "kind:function" --tsv
# Select specific columns
sqry query "kind:function" --csv --columns name,file,line,kind
# Count only (no results)
sqry query "kind:function" --count
Available columns
name, qualified_name, kind, file, line, column, end_line, end_column, language, preview
CSV safety
CSV output has formula injection protection enabled by default — cell values starting with =, +, -, or @ are prefixed with a single quote. Use --raw-csv to disable this if you’re processing output programmatically and don’t need the protection.
Code preview
Add --preview to include source code context with each result:
# Show 3 lines of context (default)
sqry query "kind:function AND name:main" --preview
# Show 5 lines of context
sqry query "kind:function AND name:main" --preview 5
# Show match line only (no surrounding context)
sqry query "kind:function AND name:main" --preview 0