Example #1
0
 /**
  * Reset terms stream
  *
  * $startId - id for the fist document
  * $compact - remove deleted documents
  *
  * Returns start document id for the next segment
  *
  * @param integer $startId
  * @param integer $mode
  * @throws \Zend\Search\Lucene\Exception\InvalidArgumentException
  * @throws \Zend\Search\Lucene\Exception\InvalidFileFormatException
  * @return integer
  */
 public function resetTermsStream()
 {
     /**
      * SegmentInfo->resetTermsStream() method actually takes two optional parameters:
      *   $startId (default value is 0)
      *   $mode (default value is self::SM_TERMS_ONLY)
      */
     $argList = func_get_args();
     if (count($argList) > 2) {
         throw new InvalidArgumentException('Wrong number of arguments');
     } else {
         if (count($argList) == 2) {
             $startId = $argList[0];
             $mode = $argList[1];
         } else {
             if (count($argList) == 1) {
                 $startId = $argList[0];
                 $mode = self::SM_TERMS_ONLY;
             } else {
                 $startId = 0;
                 $mode = self::SM_TERMS_ONLY;
             }
         }
     }
     if ($this->_tisFile !== null) {
         $this->_tisFile = null;
     }
     $this->_tisFile = $this->openCompoundFile('.tis', false);
     $this->_tisFileOffset = $this->_tisFile->tell();
     $tiVersion = $this->_tisFile->readInt();
     if ($tiVersion != (int) 0xfffffffe && $tiVersion != (int) 0xfffffffd) {
         throw new InvalidFileFormatException('Wrong TermInfoFile file format');
     }
     $this->_termCount = $this->_termNum = $this->_tisFile->readLong();
     // Read terms count
     $this->_indexInterval = $this->_tisFile->readInt();
     // Read Index interval
     $this->_skipInterval = $this->_tisFile->readInt();
     // Read skip interval
     if ($tiVersion == (int) 0xfffffffd) {
         $maxSkipLevels = $this->_tisFile->readInt();
     }
     if ($this->_frqFile !== null) {
         $this->_frqFile = null;
     }
     if ($this->_prxFile !== null) {
         $this->_prxFile = null;
     }
     $this->_docMap = array();
     $this->_lastTerm = new Term('', -1);
     $this->_lastTermInfo = new TermInfo(0, 0, 0, 0);
     $this->_lastTermPositions = null;
     $this->_termsScanMode = $mode;
     switch ($mode) {
         case self::SM_TERMS_ONLY:
             // Do nothing
             break;
         case self::SM_FULL_INFO:
             // break intentionally omitted
         // break intentionally omitted
         case self::SM_MERGE_INFO:
             $this->_frqFile = $this->openCompoundFile('.frq', false);
             $this->_frqFileOffset = $this->_frqFile->tell();
             $this->_prxFile = $this->openCompoundFile('.prx', false);
             $this->_prxFileOffset = $this->_prxFile->tell();
             for ($count = 0; $count < $this->_docCount; $count++) {
                 if (!$this->isDeleted($count)) {
                     $this->_docMap[$count] = $startId + ($mode == self::SM_MERGE_INFO ? count($this->_docMap) : $count);
                 }
             }
             break;
         default:
             throw new InvalidArgumentException('Wrong terms scaning mode specified.');
             break;
     }
     // Calculate next segment start id (since $this->_docMap structure may be cleaned by $this->nextTerm() call)
     $nextSegmentStartId = $startId + ($mode == self::SM_MERGE_INFO ? count($this->_docMap) : $this->_docCount);
     $this->nextTerm();
     return $nextSegmentStartId;
 }