Go to file
Damir Jelić fa682ab213 tantivy: Add a tox.ini file. 2019-08-08 14:22:23 +02:00
src tantivy: Disable a clippy warning about new not returning self. 2019-08-08 13:55:40 +02:00
tantivy Initial python bindings implementation. 2019-06-04 11:09:58 +02:00
tests Replace setup_class methods with pytest.fixture 2019-08-03 12:28:12 +01:00
.gitignore Fixing build. 2019-08-01 17:22:40 +09:00
Cargo.toml Cargo.toml: Use the same version as the core tantivy lib. 2019-08-03 11:51:55 +02:00
LICENSE Initial python bindings implementation. 2019-06-04 11:09:58 +02:00
MANIFEST.in Initial python bindings implementation. 2019-06-04 11:09:58 +02:00
Makefile Initial python bindings implementation. 2019-06-04 11:09:58 +02:00
README.md Fixing build. 2019-08-01 17:22:40 +09:00
pyproject.toml Initial python bindings implementation. 2019-06-04 11:09:58 +02:00
rust-toolchain Initial python bindings implementation. 2019-06-04 11:09:58 +02:00
rustfmt.toml Initial python bindings implementation. 2019-06-04 11:09:58 +02:00
setup.py setup.py: Add a description and long description. 2019-08-03 12:17:04 +02:00
tox.ini tantivy: Add a tox.ini file. 2019-08-08 14:22:23 +02:00

README.md

tantivy-py

Python bindings for tantivy.

Installation

The bindings can be installed using setuptools:

python3 setup.py install --user

Note that this requires setuptools-rust to be installed. Another thing to note is that the bindings are using PyO3, which requires rust nightly and only supports python3.

Usage

tantivy-py has 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.

    builder = tantivy.SchemaBuilder()

    title = builder.add_text_field("title", stored=True)
    body = builder.add_text_field("body")

    schema = builder.build()
    index = tantivy.Index(schema)

    writer = index.writer()

    doc = tantivy.Document()
    doc.add_text(title, "The Old Man and the Sea")
    doc.add_text(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."))
    writer.add_document(doc)
    writer.commit()
    
    reader = index.reader()
    searcher = reader.searcher()

    query_parser = tantivy.QueryParser.for_index(index, [title, body])
    query = query_parser.parse_query("sea whale")

    top_docs = tantivy.TopDocs(10)
    result = searcher.search(query, top_docs)

    _, doc_address = result[0]

    searched_doc = searcher.doc(doc_address)
    assert searched_doc.get_first(title) == "The Old Man and the Sea"