# rlean-search
Type-aware search over **Lean 4** `theorem`, `lemma`, and `axiom` declarations.
Parses `.lean` sources (not `.olean`), understands **Lake** package layout, writes
XML indexes under the schema namespace
`http://github.com/createyourpersonalaccount/rlean-search`
and answers patterns such as:
| `_ + _ = 0` | holes match any subexpression |
| `?a - ?a = 0` | named holes must unify to the same term |
| `\|- tsum _ = _ * tsum _` | match only the main conclusion |
## Build
```bash
cargo build --release
```
## Index
```bash
rlean-search index path/to/Mathlib path/to/lean4/src \
-o .rlean-search/index.xml.gz
```
The default cache is a **gzipped** XML file (`index.xml.gz`) written with the
fastest gzip compression level for quick index dumps.
Lake-aware discovery reads `lakefile.toml` / `lakefile.lean`, `srcDir`, and
`lean_lib` roots, then walks `.lean` files (skipping `.lake`, `build`, etc.).
## One-shot search (uses cache when present)
```bash
rlean-search search '_ + _ = 0' -p path/to/pkg
rlean-search search '?a - ?a = 0' -p path/to/pkg --format jsonl
```bash
# JSONL
echo '<rlean:search xmlns:rlean="http://github.com/createyourpersonalaccount/rlean-search" pattern="?a - ?a = 0" limit="20"/>' \
| nc 127.0.0.1 7878
rlean-search query --pattern '_ + 0 = _'
Commands: `search`, `stats`, `reload`, `ping`.
## XML schema
See [`schema/rlean-search.xsd`](schema/rlean-search.xsd). Index documents look like:
```xml
<rlean:index xmlns:rlean="http://github.com/createyourpersonalaccount/rlean-search" ...>
<rlean:package name="mathlib" root="...">...</rlean:package>
<rlean:declaration kind="theorem" name="add_comm" full_name="Nat.add_comm" ...>
<rlean:typeSurface>∀ (n m : Nat), n + m = m + n</rlean:typeSurface>
<rlean:type>...</rlean:type>
<rlean:conclusion head="op:=">...</rlean:conclusion>
</rlean:declaration>
</rlean:index>
```
## Tests
Fixtures under `tests/fixtures/` are derived from Lean 4 / Mathlib 4 type shapes
(from the accompanying `lean4-v4.32.2` / `mathlib4-v4.32.2` sources):
```bash
cargo test
```
## Coverage notes
The type parser targets a **useful fragment** of Lean surface types: binders,
arrows/Pi, applications, common infix operators (`+`, `*`, `=`, `≤`, `∧`, `↔`, …),
quantifiers, sorts, and search holes. Extremely advanced syntax may be stored as
`raw` nodes so declarations remain searchable by surface text and structure
where parsed.