_termStreams = $termStreams; $this->resetTermsStream(); } /** * Reset terms stream. */ public function resetTermsStream() { /** Zend_Search_Lucene_Index_TermsPriorityQueue */ require_once 'Zend/Search/Lucene/Index/TermsPriorityQueue.php'; $this->_termsStreamQueue = new Zend_Search_Lucene_Index_TermsPriorityQueue(); foreach ($this->_termStreams as $termStream) { $termStream->resetTermsStream(); // Skip "empty" containers if ($termStream->currentTerm() !== null) { $this->_termsStreamQueue->put($termStream); } } $this->nextTerm(); } /** * Skip terms stream up to specified term preffix. * * Prefix contains fully specified field info and portion of searched term * * @param Zend_Search_Lucene_Index_Term $prefix */ public function skipTo(Zend_Search_Lucene_Index_Term $prefix) { $termStreams = array(); while (($termStream = $this->_termsStreamQueue->pop()) !== null) { $termStreams[] = $termStream; } foreach ($termStreams as $termStream) { $termStream->skipTo($prefix); if ($termStream->currentTerm() !== null) { $this->_termsStreamQueue->put($termStream); } } $this->nextTerm(); } /** * Scans term streams and returns next term * * @return Zend_Search_Lucene_Index_Term|null */ public function nextTerm() { while (($termStream = $this->_termsStreamQueue->pop()) !== null) { if ($this->_termsStreamQueue->top() === null || $this->_termsStreamQueue->top()->currentTerm()->key() != $termStream->currentTerm()->key()) { // We got new term $this->_lastTerm = $termStream->currentTerm(); if ($termStream->nextTerm() !== null) { // Put segment back into the priority queue $this->_termsStreamQueue->put($termStream); } return $this->_lastTerm; } if ($termStream->nextTerm() !== null) { // Put segment back into the priority queue $this->_termsStreamQueue->put($termStream); } } // End of stream $this->_lastTerm = null; return null; } /** * Returns term in current position * * @return Zend_Search_Lucene_Index_Term|null */ public function currentTerm() { return $this->_lastTerm; } /** * Close terms stream * * Should be used for resources clean up if stream is not read up to the end */ public function closeTermsStream() { while (($termStream = $this->_termsStreamQueue->pop()) !== null) { $termStream->closeTermsStream(); } $this->_termsStreamQueue = null; $this->_lastTerm = null; } }