Adding delete_all_documents method for IndexWriter (#133)

master
Stone 2023-09-28 05:42:38 +08:00 committed by GitHub
parent 6340564cd4
commit 4af7d7c45f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 0 deletions

View File

@ -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

View File

@ -488,6 +488,18 @@ class TestClass(object):
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):