[Xapian-discuss] how to delete all document from the DB (without deleting the DB itself)

Richard Boulton richard at lemurconsulting.com
Thu Apr 24 19:09:21 BST 2008


Alessandro Pasotti wrote:
> Hello,
> 
> I'm still testing PHP5 bindings and I could'nt find a way to delete
> all documents from a DB without deleting other informations stored in
> the DB such as synonyms.
> 
> Since the process of adding synonyms is time consuming, I would like
> to use the same DB but restart my test without any document in the DB,
> is this possibile?
> 
> I could'nt find a delete_all or a method like that, nor an iterator
> over all documents without querying.

There isn't a delete_all() method, but there is a way to get an iterator 
over all the documents in the database.

In C++, you simply need to use the Database::postlist_begin() method 
with an empty string - this will return a PostingIterator which returns 
all the document IDs in the database.  You can then call delete document 
on them.

This is wrapped in the normal way in the PHP bindings.

For your particular case, another approach is to first add all the 
synonyms to a clean database, flush, and then for each test you could 
create your test database by make a copy of that database (using 
standard file copy operations to copy the database directory).

-- 
Richard



More information about the Xapian-discuss mailing list