doc/lib: Fix DocSearchIterator::count() counting too many

Because DocSearchIterator is a recursive filter iterator and we accept
any hode having children, those children not matching any of the search criteria
were counted too because of iterator_count.

refs #6630
This commit is contained in:
Eric Lippmann 2015-02-11 13:03:46 +01:00
parent 21b65d8079
commit 1053e62e20

View File

@ -50,7 +50,7 @@ class DocSearchIterator extends RecursiveFilterIterator implements Countable
*/ */
public function accept() public function accept()
{ {
$section = $this->getInnerIterator()->current(); $section = $this->current();
/** @type $section \Icinga\Module\Doc\DocSection */ /** @type $section \Icinga\Module\Doc\DocSection */
$matches = array(); $matches = array();
if (($match = $this->search->search($section->getTitle())) !== null) { if (($match = $this->search->search($section->getTitle())) !== null) {
@ -97,7 +97,13 @@ class DocSearchIterator extends RecursiveFilterIterator implements Countable
*/ */
public function count() public function count()
{ {
return iterator_count($this); $count = 0;
foreach ($this as $section) {
if ($this->getMatches() !== null) {
++$count;
}
}
return $count;
} }
/** /**