Skip to content

Commit

Permalink
Adding delete_all_documents method for IndexWriter (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
st1020 authored Sep 27, 2023
1 parent 6340564 commit 4af7d7c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ impl IndexWriter {
Ok(())
}

/// Deletes all documents from the index.
fn delete_all_documents(&mut self) -> PyResult<()> {
self.inner()?.delete_all_documents().map_err(to_pyerr)?;
Ok(())
}

/// The opstamp of the last successful commit.
///
/// This is the opstamp the index will rollback to if there is a failure
Expand Down
12 changes: 12 additions & 0 deletions tests/tantivy_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,18 @@ def test_search_result_pickle(self, ram_index):

assert orig == pickled

def test_delete_all_documents(self, ram_index):
index = ram_index
writer = index.writer()
writer.delete_all_documents()
writer.commit()

index.reload()
query = index.parse_query("sea whale", ["title", "body"])
result = index.searcher().search(query, 10)

assert len(result.hits) == 0


class TestUpdateClass(object):
def test_delete_update(self, ram_index):
Expand Down

0 comments on commit 4af7d7c

Please sign in to comment.