larzsearch
Full-text search with real relevance (BM25). Pure Python, zero dependencies.
Index documents, then search them ranked by BM25 — the relevance model behind Lucene and Elasticsearch — not just "contains the word". Rarer query terms count for more, term frequency has diminishing returns, and long documents don't win by length. Optional fuzzy matching tolerates typos.
from larzsearch import SearchIndex
idx = SearchIndex()
idx.add("a", "the quick brown fox jumps")
idx.add("b", "the lazy brown dog sleeps")
idx.search("brown fox") # [{'id': 'a', 'score': .., 'doc': ..}, ...]
idx.search("quik fox", fuzzy=True) # matches despite the typo
Why
- Actual ranking, not filtering. BM25 with IDF weighting and length normalization gives you results ordered by relevance — the thing naive substring search can't do.
- Typo-tolerant.
fuzzy=Truematches query terms within one edit, so "pythou" finds "python". - Documents your way. Index plain strings or dicts (all values are indexed); the original doc comes back with each result.
- Zero dependencies. No Elasticsearch, no Whoosh, no C extensions — great for in-app search, docs sites, CLIs, and pairing with larzdb.
Install
pip install larzsearch
Usage
idx = SearchIndex(k1=1.5, b=0.75) # tune BM25 if you like
idx.add("doc1", "text ...")
idx.add("doc2", {"title": "...", "body": "..."})
idx.add_many([{"id": 1, "text": "..."}, ...])
idx.remove("doc1"); idx.get("doc2"); len(idx)
results = idx.search("query terms", limit=10, fuzzy=False)
# [{"id": ..., "score": float, "doc": original}, ...] (best first)
Tests
python -m unittest discover -s tests -v # 15 tests incl. ranking + fuzzy
The Larz stack
One of 30+ pure-Python, zero-dependency libraries at github.com/larz-scripter.
License
MIT © larz-scripter
Release files for larzsearch 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| larzsearch-0.1.0.tar.gz | 6.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| larzsearch-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 12.0 kB
Release files / larzsearch-0.1.0.tar.gz
| Download URL | larzsearch-0.1.0.tar.gz |
|---|---|
| Size | 6.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
eab6d43b155862cc5b08ff593130b517906f3217c23279a17c0cc33585a26ef9
|
|
BLAKE2b-256 checksum How to use checksums |
237850c78e96041003df9b39366845351f4329ed592e1b44e022b3ab565988d3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.13
|
Release files / larzsearch-0.1.0-py3-none-any.whl
| Download URL | larzsearch-0.1.0-py3-none-any.whl |
|---|---|
| Size | 6.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7efde94ce518fde89511ae4c2b2bf21e23a6c58d6d9465121f9192e83a91d368
|
|
BLAKE2b-256 checksum How to use checksums |
f3da0d78a28ccf270e77bc1da917727274e3f4057b26225a85c7e8e4b9e28375
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.13
|