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
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file larzsearch-0.1.0.tar.gz.
File metadata
- Download URL: larzsearch-0.1.0.tar.gz
- Upload date:
- Size: 6.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eab6d43b155862cc5b08ff593130b517906f3217c23279a17c0cc33585a26ef9
|
|
| MD5 |
dd2be8bbbf2389a483a4f2b613a247f7
|
|
| BLAKE2b-256 |
237850c78e96041003df9b39366845351f4329ed592e1b44e022b3ab565988d3
|
File details
Details for the file larzsearch-0.1.0-py3-none-any.whl.
File metadata
- Download URL: larzsearch-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7efde94ce518fde89511ae4c2b2bf21e23a6c58d6d9465121f9192e83a91d368
|
|
| MD5 |
7c0b0585f082bd1d7677bc6ce46d158c
|
|
| BLAKE2b-256 |
f3da0d78a28ccf270e77bc1da917727274e3f4057b26225a85c7e8e4b9e28375
|