当前位置: 首页>>代码示例>>PHP>>正文


PHP Zend_Search_Lucene_Search_Similarity::getDefault方法代码示例

本文整理汇总了PHP中Zend_Search_Lucene_Search_Similarity::getDefault方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Search_Lucene_Search_Similarity::getDefault方法的具体用法?PHP Zend_Search_Lucene_Search_Similarity::getDefault怎么用?PHP Zend_Search_Lucene_Search_Similarity::getDefault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend_Search_Lucene_Search_Similarity的用法示例。


在下文中一共展示了Zend_Search_Lucene_Search_Similarity::getDefault方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: addDocument

 /**
  * Adds a document to this segment.
  *
  * @param Zend_Search_Lucene_Document $document
  * @throws Zend_Search_Lucene_Exception
  */
 public function addDocument(Zend_Search_Lucene_Document $document)
 {
     $storedFields = array();
     $docNorms = array();
     $similarity = Zend_Search_Lucene_Search_Similarity::getDefault();
     foreach ($document->getFieldNames() as $fieldName) {
         $field = $document->getField($fieldName);
         $this->addField($field);
         if ($field->storeTermVector) {
             /**
              * @todo term vector storing support
              */
             throw new Zend_Search_Lucene_Exception('Store term vector functionality is not supported yet.');
         }
         if ($field->isIndexed) {
             if ($field->isTokenized) {
                 $tokenList = Zend_Search_Lucene_Analysis_Analyzer::getDefault()->tokenize($field->stringValue);
             } else {
                 $tokenList = array();
                 $tokenList[] = new Zend_Search_Lucene_Analysis_Token($field->stringValue, 0, strlen($field->stringValue));
             }
             $docNorms[$field->name] = chr($similarity->encodeNorm($similarity->lengthNorm($field->name, count($tokenList))));
             $position = 0;
             foreach ($tokenList as $token) {
                 $term = new Zend_Search_Lucene_Index_Term($token->getTermText(), $field->name);
                 $termKey = $term->key();
                 if (!isset($this->_termDictionary[$termKey])) {
                     // New term
                     $this->_termDictionary[$termKey] = $term;
                     $this->_termDocs[$termKey] = array();
                     $this->_termDocs[$termKey][$this->_docCount] = array();
                 } else {
                     if (!isset($this->_termDocs[$termKey][$this->_docCount])) {
                         // Existing term, but new term entry
                         $this->_termDocs[$termKey][$this->_docCount] = array();
                     }
                 }
                 $position += $token->getPositionIncrement();
                 $this->_termDocs[$termKey][$this->_docCount][] = $position;
             }
         }
         if ($field->isStored) {
             $storedFields[] = $field;
         }
     }
     foreach ($this->_fields as $fieldName => $field) {
         if (!$field->isIndexed) {
             continue;
         }
         if (!isset($this->_norms[$fieldName])) {
             $this->_norms[$fieldName] = str_repeat(chr($similarity->encodeNorm($similarity->lengthNorm($fieldName, 0))), $this->_docCount);
         }
         if (isset($docNorms[$fieldName])) {
             $this->_norms[$fieldName] .= $docNorms[$fieldName];
         } else {
             $this->_norms[$fieldName] .= chr($similarity->encodeNorm($similarity->lengthNorm($fieldName, 0)));
         }
     }
     $this->addStoredFields($storedFields);
 }
开发者ID:BackupTheBerlios,项目名称:openpublisher-svn,代码行数:66,代码来源:DocumentWriter.php

示例2: normVector

    /**
     * Returns norm vector, encoded in a byte string
     *
     * @param string $fieldName
     * @return string
     */
    public function normVector($fieldName)
    {
        $fieldNum = $this->getFieldNum($fieldName);

        if ($fieldNum == -1  ||  !($this->_fields[$fieldNum]->isIndexed)) {
            $similarity = Zend_Search_Lucene_Search_Similarity::getDefault();

            return str_repeat(chr($similarity->encodeNorm( $similarity->lengthNorm($fieldName, 0) )),
                              $this->_docCount);
        }

        if (!isset($this->_norms[$fieldNum])) {
            $this->_loadNorm($fieldNum);
        }

        return $this->_norms[$fieldNum];
    }
开发者ID:realfluid,项目名称:umbaugh,代码行数:23,代码来源:SegmentInfo.php

示例3: getSimilarity

 public function getSimilarity()
 {
     return Zend_Search_Lucene_Search_Similarity::getDefault();
 }
开发者ID:hackingman,项目名称:TubeX,代码行数:4,代码来源:Lucene.php

示例4: addDocument

 /**
  * Adds a document to this segment.
  *
  * @param Zend_Search_Lucene_Document $document
  * @throws Zend_Search_Lucene_Exception
  */
 public function addDocument(Zend_Search_Lucene_Document $document)
 {
     /** Zend_Search_Lucene_Search_Similarity */
     // require_once 'Zend/Search/Lucene/Search/Similarity.php';
     $storedFields = array();
     $docNorms = array();
     $similarity = Zend_Search_Lucene_Search_Similarity::getDefault();
     foreach ($document->getFieldNames() as $fieldName) {
         $field = $document->getField($fieldName);
         if ($field->storeTermVector) {
             /**
              * @todo term vector storing support
              */
             // require_once 'Zend/Search/Lucene/Exception.php';
             throw new Zend_Search_Lucene_Exception('Store term vector functionality is not supported yet.');
         }
         if ($field->isIndexed) {
             if ($field->isTokenized) {
                 /** Zend_Search_Lucene_Analysis_Analyzer */
                 // require_once 'Zend/Search/Lucene/Analysis/Analyzer.php';
                 $analyzer = Zend_Search_Lucene_Analysis_Analyzer::getDefault();
                 $analyzer->setInput($field->value, $field->encoding);
                 $position = 0;
                 $tokenCounter = 0;
                 while (($token = $analyzer->nextToken()) !== null) {
                     $tokenCounter++;
                     $term = new Zend_Search_Lucene_Index_Term($token->getTermText(), $field->name);
                     $termKey = $term->key();
                     if (!isset($this->_termDictionary[$termKey])) {
                         // New term
                         $this->_termDictionary[$termKey] = $term;
                         $this->_termDocs[$termKey] = array();
                         $this->_termDocs[$termKey][$this->_docCount] = array();
                     } else {
                         if (!isset($this->_termDocs[$termKey][$this->_docCount])) {
                             // Existing term, but new term entry
                             $this->_termDocs[$termKey][$this->_docCount] = array();
                         }
                     }
                     $position += $token->getPositionIncrement();
                     $this->_termDocs[$termKey][$this->_docCount][] = $position;
                 }
                 if ($tokenCounter == 0) {
                     // Field contains empty value. Treat it as non-indexed and non-tokenized
                     $field = clone $field;
                     $field->isIndexed = $field->isTokenized = false;
                 } else {
                     $docNorms[$field->name] = chr($similarity->encodeNorm($similarity->lengthNorm($field->name, $tokenCounter) * $document->boost * $field->boost));
                 }
             } else {
                 if (($fieldUtf8Value = $field->getUtf8Value()) == '') {
                     // Field contains empty value. Treat it as non-indexed and non-tokenized
                     $field = clone $field;
                     $field->isIndexed = $field->isTokenized = false;
                 } else {
                     $term = new Zend_Search_Lucene_Index_Term($fieldUtf8Value, $field->name);
                     $termKey = $term->key();
                     if (!isset($this->_termDictionary[$termKey])) {
                         // New term
                         $this->_termDictionary[$termKey] = $term;
                         $this->_termDocs[$termKey] = array();
                         $this->_termDocs[$termKey][$this->_docCount] = array();
                     } else {
                         if (!isset($this->_termDocs[$termKey][$this->_docCount])) {
                             // Existing term, but new term entry
                             $this->_termDocs[$termKey][$this->_docCount] = array();
                         }
                     }
                     $this->_termDocs[$termKey][$this->_docCount][] = 0;
                     // position
                     $docNorms[$field->name] = chr($similarity->encodeNorm($similarity->lengthNorm($field->name, 1) * $document->boost * $field->boost));
                 }
             }
         }
         if ($field->isStored) {
             $storedFields[] = $field;
         }
         $this->addField($field);
     }
     foreach ($this->_fields as $fieldName => $field) {
         if (!$field->isIndexed) {
             continue;
         }
         if (!isset($this->_norms[$fieldName])) {
             $this->_norms[$fieldName] = str_repeat(chr($similarity->encodeNorm($similarity->lengthNorm($fieldName, 0))), $this->_docCount);
         }
         if (isset($docNorms[$fieldName])) {
             $this->_norms[$fieldName] .= $docNorms[$fieldName];
         } else {
             $this->_norms[$fieldName] .= chr($similarity->encodeNorm($similarity->lengthNorm($fieldName, 0)));
         }
     }
     $this->addStoredFields($storedFields);
 }
开发者ID:jkimdon,项目名称:cohomeals,代码行数:100,代码来源:DocumentWriter.php

示例5: getSimilarity

 /**
  * Retrive similarity used by index reader
  *
  * @return Zend_Search_Lucene_Search_Similarity
  */
 public function getSimilarity()
 {
     /** Zend_Search_Lucene_Search_Similarity */
     // require_once 'Zend/Search/Lucene/Search/Similarity.php';
     return Zend_Search_Lucene_Search_Similarity::getDefault();
 }
开发者ID:alefernie,项目名称:intranet,代码行数:11,代码来源:Lucene.php

示例6: find

 public function find()
 {
     if ($this->e) {
         throw new Exception('Because you said so');
     }
     $this->args = func_get_args();
     $this->scoring = Zend_Search_Lucene_Search_Similarity::getDefault();
     return range(1, 100);
 }
开发者ID:palcoprincipal,项目名称:sfLucenePlugin,代码行数:9,代码来源:sfLuceneTest.php

示例7: find

 /**
  * Wrapper for Lucene's find()
  * @param mixed $query The query
  * @return array The array of results
  */
 public function find($query)
 {
     $this->configure();
     $timer = sfTimerManager::getTimer('Zend Search Lucene Find');
     $sort = array();
     $scoring = null;
     if ($query instanceof sfLuceneCriteria) {
         foreach ($query->getSorts() as $sortable) {
             $sort[] = $sortable['field'];
             $sort[] = $sortable['type'];
             $sort[] = $sortable['order'];
         }
         $scoring = $query->getScoringAlgorithm();
         $query = $query->getQuery();
     } elseif (is_string($query)) {
         $query = sfLuceneCriteria::newInstance($this)->addString($query)->getQuery();
     }
     $defaultScoring = Zend_Search_Lucene_Search_Similarity::getDefault();
     if ($scoring) {
         Zend_Search_Lucene_Search_Similarity::setDefault($scoring);
     }
     try {
         // as we rarely sort, we can avoid the overhead of call_user_func() with this conditional
         if (count($sort)) {
             $args = array_merge(array($query), $sort);
             $results = call_user_func_array(array($this->getLucene(), 'find'), $args);
         } else {
             $results = $this->getLucene()->find($query);
         }
     } catch (Exception $e) {
         Zend_Search_Lucene_Search_Similarity::setDefault($defaultScoring);
         $timer->addTime();
         throw $e;
     }
     Zend_Search_Lucene_Search_Similarity::setDefault($defaultScoring);
     $timer->addTime();
     return $results;
 }
开发者ID:palcoprincipal,项目名称:sfLucenePlugin,代码行数:43,代码来源:sfLucene.class.php

示例8: getSimilarity

 /**
  * Retrive similarity used by index reader
  *
  * @return Zend_Search_Lucene_Search_Similarity
  */
 public function getSimilarity()
 {
     /** Zend_Search_Lucene_Search_Similarity */
     require_once sfConfig::get('sf_lib_dir') . '/modules/search/lib/Lucene/Search/Similarity.php';
     return Zend_Search_Lucene_Search_Similarity::getDefault();
 }
开发者ID:kotow,项目名称:work,代码行数:11,代码来源:Lucene.php

示例9: _dumpFNM

 /**
  * Dump Field Info (.fnm) segment file
  */
 private function _dumpFNM()
 {
     $fnmFile = $this->_directory->createFile($this->_name . '.fnm');
     $fnmFile->writeVInt(count($this->_fields));
     foreach ($this->_fields as $field) {
         $fnmFile->writeString($field->name);
         $fnmFile->writeByte(($field->isIndexed ? 0x1 : 0x0) | ($field->storeTermVector ? 0x2 : 0x0));
         if ($field->isIndexed) {
             $fieldNum = $this->_fields[$field->name]->number;
             $fieldName = $field->name;
             $similarity = Zend_Search_Lucene_Search_Similarity::getDefault();
             $norm = '';
             for ($count = 0; $count < $this->_docCount; $count++) {
                 $numTokens = isset($this->_fieldLengths[$fieldName][$count]) ? $this->_fieldLengths[$fieldName][$count] : 0;
                 $norm .= chr($similarity->encodeNorm($similarity->lengthNorm($fieldName, $numTokens)));
             }
             $normFileName = $this->_name . '.f' . $fieldNum;
             $fFile = $this->_directory->createFile($normFileName);
             $fFile->writeBytes($norm);
             $this->_files[] = $normFileName;
         }
     }
     $this->_files[] = $this->_name . '.fnm';
 }
开发者ID:BackupTheBerlios,项目名称:umlrecord,代码行数:27,代码来源:SegmentWriter.php


注:本文中的Zend_Search_Lucene_Search_Similarity::getDefault方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。