No project description provided
Project description
tantivy-py
Python bindings for Tantivy.
Installation
The bindings can be installed using from pypi using pip:
pip install tantivy
If no binary wheel is present for your operating system the bindings will be build from source, this means that Rust needs to be installed before building can succeed.
Note that the bindings are using PyO3, which requires rust nightly and only supports python3.
Development
Setting up a development enviroment can be done in a virtual environment using
pipenv
or using local packages using the provided Makefile
.
For the pipenv
setup install the virtual environment and build the bindings using:
pipenv install --dev
pipenv run maturin develop
After the bindings are build, the tests can be run using:
pipenv run python -m pytest
For the Makefile
based setup run:
make
Running the tests is done using:
make test
Usage
The Python bindings have a similar API to Tantivy. To create a index first a schema needs to be built. After that documents can be added to the index and a reader can be created to search the index.
import tantivy
# Declaring our schema.
schema_builder = tantivy.SchemaBuilder()
schema_builder.add_text_field("title", stored=True)
schema_builder.add_text_field("body", stored=True)
schema = schema_builder.build()
# Creating our index (in memory, but filesystem is available too)
index = tantivy.Index(schema)
# Adding one document.
writer = index.writer()
writer.add_document(tantivy.Document(
title=["The Old Man and the Sea"],
body=["""He was an old man who fished alone in a skiff in the Gulf Stream and he had gone eighty-four days now without taking a fish."""],
))
# ... and committing
writer.commit()
# Reload the index to ensure it points to the last commit.
index.reload()
searcher = index.searcher()
query = index.parse_query("fish days", ["title", "body"])
(best_score, best_doc_address) = searcher.search(query, 3).hits[0]
best_doc = searcher.doc(best_doc_address)
assert best_doc["title"] == ["The Old Man and the Sea"]
print(best_doc)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for tantivy-0.13.1_rc.1-cp38-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b759054bf275cf76b8798923bff1460b2981e289f52054c2e24d51a86367ee3f |
|
MD5 | 692fd571022036b388df8a0bb1868a86 |
|
BLAKE2b-256 | 74d2973a78f9f4e92efb9c56c1eb64465fc64e230bf67805c9ed2846d0f029f6 |
Hashes for tantivy-0.13.1_rc.1-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 58226ec8b137a99dbf3c28507222d14bf6ab0d1a3c3d0e3992d451b2bd16cf5d |
|
MD5 | c1d2c1dd152940afb2c5f762bb9e0064 |
|
BLAKE2b-256 | 74429bbcf90723a7632e141becebf0fa82aa55a866bf23fb1d38c3728709b480 |
Hashes for tantivy-0.13.1_rc.1-cp38-cp38-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ec5dbf64bd1b2d8a27719feb722a1c5824793b69c052a16eadc036a342ab969c |
|
MD5 | 00a6bd4bf26fa85bdb534d0bc02f52c9 |
|
BLAKE2b-256 | 190021d39099183ff5ad833c52bd37f38fa9dbca4b84ac15e76d575c8311391a |
Hashes for tantivy-0.13.1_rc.1-cp37-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c7013c30ff66ca1417b36496b9b5ff296f5c01f087bc8745fec289da3e732386 |
|
MD5 | 2d4744a73543d808f2604859387c13f0 |
|
BLAKE2b-256 | 1df1f296e5ba7ddddb5084b1633529d419b47bdf1fac6de1ed77c64285231d48 |
Hashes for tantivy-0.13.1_rc.1-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 46bb17e531f20289b83f6499a270d78ef48803e6c97d21ae839bddf5270ec56c |
|
MD5 | e7938e081969336d43c25f2cc1604c2f |
|
BLAKE2b-256 | 204544ae0e279ec79f50818c22561bd569260e265851baff18fa7836bb66c1ce |
Hashes for tantivy-0.13.1_rc.1-cp37-cp37m-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 84a3821de63ec7857c999c754fd906392039a38a5efc2de26a27f44ebb6bca31 |
|
MD5 | 87fa1476910de3ea72da23406fbbc302 |
|
BLAKE2b-256 | a4e6dbc933a7de291bef6cbf8c050c075e8b463a64946d4494a2451aebd5a011 |