PhpRiot
Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...


When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Retrieving Index Size

There are two methods to retrieve the size of an index in Zend_Search_Lucene.

Zend_Search_Lucene::maxDoc() returns one greater than the largest possible document number. It's actually the overall number of the documents in the index including deleted documents, so it has a synonym: Zend_Search_Lucene::count().

Zend_Search_Lucene::numDocs() returns the total number of non-deleted documents.

<?php
$indexSize 
$index->count();
$documents $index->numDocs();

Zend_Search_Lucene::isDeleted($id) method may be used to check if a document is deleted.

<?php
for ($count 0$count $index->maxDoc(); $count++) {
    if (
$index->isDeleted($count)) {
        echo 
"Document #$id is deleted.\n";
    }
}

Index optimization removes deleted documents and squeezes documents' IDs in to a smaller range. A document's internal id may therefore change during index optimization.

Zend Framework