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.12.0_rc.2-cp38-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4ee4968163fa702d12f9e3e0227c8c00acb6e32fbbd7cbd651a739789923cae7 |
|
MD5 | abf1111de8912c4afbb93617c346df0a |
|
BLAKE2b-256 | 2a754554c1b7a5848d09b9ac7a2fa94ec8fc08f16b8eda1f81e992d5bad6f630 |
Hashes for tantivy-0.12.0_rc.2-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a8b4d03253319108956f5b0fef7a56ee6287c28ff1cb1bc1d48b3d006a19fee9 |
|
MD5 | 07f85ce034b94b68f37ab753080aa83d |
|
BLAKE2b-256 | 8ac2bfc646d16d57c47fae02c4bc6327700e7b47222492cd7ab142bbb3387df7 |
Hashes for tantivy-0.12.0_rc.2-cp38-cp38-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8b4dbf3b60bf149476b18ae3880a99e2a3c0b3ef8a8886594f269aaf81b8ed2f |
|
MD5 | bf47cc8ad5c5ebb8206f6421d4b1fb76 |
|
BLAKE2b-256 | ef9813648b3958394124945298c7f0ae9dfea17303db58853148eadab620bef9 |
Hashes for tantivy-0.12.0_rc.2-cp37-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ed29f3d3eed2e87557c46baac75261c05490cd01012139e75a214bffb709465d |
|
MD5 | efdfb13e888d8f8140d0a7971d10e7a4 |
|
BLAKE2b-256 | ceeedabc7795e1e9432279403c3703b7fd5ac77d45b05d1f5f20797663f5bfcd |
Hashes for tantivy-0.12.0_rc.2-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dd6477a172a91bfe887b64269ce529af9b03479b8cf367cd1e17e970ad06c921 |
|
MD5 | 2603de6e89f107be6e271f19aeeb4a75 |
|
BLAKE2b-256 | 3d4fd9f1defee3667a65fcb0076982280f0a07f79b62af3411a19e67e35af494 |
Hashes for tantivy-0.12.0_rc.2-cp37-cp37m-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 94e54239535cd850cb9220821eec0756470302b60a88fced7c6a515f7c1f6a3f |
|
MD5 | 2ebae3424961f0046f131d3093f65ef3 |
|
BLAKE2b-256 | 11c5f7392f9ae965998b5b0eec28ea897eaf99449edda0f34129d95b194ac87e |