Skip to content

How to load persisted tantivy index? #195

Answered by cjrh
JRatschat asked this question in Q&A
Discussion options

You must be logged in to vote

Thank you for pointing this out. It's just an oversight in the documentation.

There is an open() staticmethod on the Index class that loads an index from a directory path. You can see this by looking at the code for the Index class:

#[pyclass(module = "tantivy.tantivy")]
pub(crate) struct Index {
    pub(crate) index: tv::Index,
    reader: tv::IndexReader,
}

#[pymethods]
impl Index {
    #[staticmethod]
    fn open(path: &str) -> PyResult<Index> {
        let index = tv::Index::open_in_dir(path).map_err(to_pyerr)?;

        Index::register_custom_text_analyzers(&index);

        let reader = index.reader().map_err(to_pyerr)?;
        Ok(Index { index, reader })
    }

Here's a worked exa…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@JRatschat
Comment options

Answer selected by JRatschat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants