コード例 #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 boolean $compact
  * @throws Zend_Search_Lucene_Exception
  * @return integer
  */
 public function reset($startId = 0, $compact = false)
 {
     if ($this->_tisFile !== null) {
         $this->_tisFile = null;
     }
     $this->_tisFile = $this->openCompoundFile('.tis', false);
     $tiVersion = $this->_tisFile->readInt();
     if ($tiVersion != (int) 0.0) {
         throw new Zend_Search_Lucene_Exception('Wrong TermInfoFile file format');
     }
     $this->_termCount = $this->_tisFile->readLong();
     $this->_tisFile->readInt();
     // Read Index interval
     $this->_skipInterval = $this->_tisFile->readInt();
     // Read skip interval
     if ($this->_frqFile !== null) {
         $this->_frqFile = null;
     }
     $this->_frqFile = $this->openCompoundFile('.frq', false);
     $this->_frqFileOffset = $this->_frqFile->tell();
     if ($this->_prxFile !== null) {
         $this->_prxFile = null;
     }
     $this->_prxFile = $this->openCompoundFile('.prx', false);
     $this->_prxFileOffset = $this->_prxFile->tell();
     $this->_lastTerm = new Zend_Search_Lucene_Index_Term('', -1);
     $this->_lastTermInfo = new Zend_Search_Lucene_Index_TermInfo(0, 0, 0, 0);
     $this->_docMap = array();
     for ($count = 0; $count < $this->_docCount; $count++) {
         if (!$this->isDeleted($count)) {
             $this->_docMap[$count] = $startId + ($compact ? count($this->_docMap) : $count);
         }
     }
     $this->nextTerm();
     return $startId + ($compact ? count($this->_docMap) : $this->_docCount);
 }
コード例 #2
0
ファイル: SegmentInfo.php プロジェクト: realfluid/umbaugh
    /**
     * 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
     * @return integer
     */
    public function resetTermsStream(/** $startId = 0, $mode = self::SM_TERMS_ONLY */)
    {
    	/**
    	 * 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) {
            require_once 'Zend/Search/Lucene/Exception.php';
            throw new Zend_Search_Lucene_Exception('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 /* pre-2.1 format */  &&
            $tiVersion != (int)0xFFFFFFFD /* 2.1+ format    */) {
            require_once 'Zend/Search/Lucene/Exception.php';
            throw new Zend_Search_Lucene_Exception('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 /* 2.1+ format */) {
            $maxSkipLevels = $this->_tisFile->readInt();
        }

        if ($this->_frqFile !== null) {
            $this->_frqFile = null;
        }
        if ($this->_prxFile !== null) {
            $this->_prxFile = null;
        }
        $this->_docMap = array();

        $this->_lastTerm          = new Zend_Search_Lucene_Index_Term('', -1);
        $this->_lastTermInfo      = new Zend_Search_Lucene_Index_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
            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:
                require_once 'Zend/Search/Lucene/Exception.php';
                throw new Zend_Search_Lucene_Exception('Wrong terms scaning mode specified.');
                break;
        }


        $this->nextTerm();
        return $startId + (($mode == self::SM_MERGE_INFO) ? count($this->_docMap) : $this->_docCount);
    }
コード例 #3
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
  * @return integer
  */
 public function reset($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) {
         require_once 'Zend/Search/Lucene/Exception.php';
         throw new Zend_Search_Lucene_Exception('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 Zend_Search_Lucene_Index_Term('', -1);
     $this->_lastTermInfo = new Zend_Search_Lucene_Index_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:
             require_once 'Zend/Search/Lucene/Exception.php';
             throw new Zend_Search_Lucene_Exception('Wrong terms scaning mode specified.');
             break;
     }
     $this->nextTerm();
     return $startId + ($mode == self::SM_MERGE_INFO ? count($this->_docMap) : $this->_docCount);
 }