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


PHP Zend_Search_Lucene::getSimilarity方法代码示例

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


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

示例1: sumOfSquaredWeights

 /**
  * The sum of squared weights of contained query clauses.
  *
  * @return float
  */
 public function sumOfSquaredWeights()
 {
     // compute idf
     $this->_idf = $this->_reader->getSimilarity()->idf($this->_term, $this->_reader);
     // compute query weight
     $this->_queryWeight = $this->_idf * $this->_query->getBoost();
     // square it
     return $this->_queryWeight * $this->_queryWeight;
 }
开发者ID:BackupTheBerlios,项目名称:openpublisher-svn,代码行数:14,代码来源:Term.php

示例2: _nonConjunctionScore

 /**
  * Score calculator for non conjunction queries (not all terms are required)
  *
  * @param integer $docId
  * @param Zend_Search_Lucene $reader
  * @return float
  */
 public function _nonConjunctionScore($docId, $reader)
 {
     if ($this->_coord === null) {
         $this->_coord = array();
         $maxCoord = 0;
         foreach ($this->_signs as $sign) {
             if ($sign !== false) {
                 $maxCoord++;
             }
         }
         for ($count = 0; $count <= $maxCoord; $count++) {
             $this->_coord[$count] = $reader->getSimilarity()->coord($count, $maxCoord);
         }
     }
     $score = 0.0;
     $matchedTerms = 0;
     foreach ($this->_terms as $termId => $term) {
         // Check if term is
         if ($this->_signs[$termId] !== false && isset($this->_termsPositions[$termId][$docId])) {
             $matchedTerms++;
             $score += $reader->getSimilarity()->tf(count($this->_termsPositions[$termId][$docId])) * $this->_weights[$termId]->getValue() * $reader->norm($docId, $term->field);
         }
     }
     return $score * $this->_coord[$matchedTerms];
 }
开发者ID:Nurudeen,项目名称:prado,代码行数:32,代码来源:MultiTerm.php

示例3: _sloppyPhraseFreq

 /**
  * Score calculator for sloppy phrase queries (terms sequence is fixed)
  *
  * @param integer $docId
  * @param Zend_Search_Lucene $reader
  * @return float
  */
 public function _sloppyPhraseFreq($docId, Zend_Search_Lucene $reader)
 {
     $freq = 0;
     $phraseQueue = array();
     $phraseQueue[0] = array();
     // empty phrase
     $lastTerm = null;
     // Walk through the terms to create phrases.
     foreach ($this->_terms as $termId => $term) {
         $queueSize = count($phraseQueue);
         $firstPass = true;
         // Walk through the term positions.
         // Each term position produces a set of phrases.
         foreach ($this->_termsPositions[$termId][$docId] as $termPosition) {
             if ($firstPass) {
                 for ($count = 0; $count < $queueSize; $count++) {
                     $phraseQueue[$count][$termId] = $termPosition;
                 }
             } else {
                 for ($count = 0; $count < $queueSize; $count++) {
                     if ($lastTerm !== null && abs($termPosition - $phraseQueue[$count][$lastTerm] - ($this->_offsets[$termId] - $this->_offsets[$lastTerm])) > $this->_slop) {
                         continue;
                     }
                     $newPhraseId = count($phraseQueue);
                     $phraseQueue[$newPhraseId] = $phraseQueue[$count];
                     $phraseQueue[$newPhraseId][$termId] = $termPosition;
                 }
             }
             $firstPass = false;
         }
         $lastTerm = $termId;
     }
     foreach ($phraseQueue as $phrasePos) {
         $minDistance = null;
         for ($shift = -$this->_slop; $shift <= $this->_slop; $shift++) {
             $distance = 0;
             $start = reset($phrasePos) - reset($this->_offsets) + $shift;
             foreach ($this->_terms as $termId => $term) {
                 $distance += abs($phrasePos[$termId] - $this->_offsets[$termId] - $start);
                 if ($distance > $this->_slop) {
                     break;
                 }
             }
             if ($minDistance === null || $distance < $minDistance) {
                 $minDistance = $distance;
             }
         }
         if ($minDistance <= $this->_slop) {
             $freq += $reader->getSimilarity()->sloppyFreq($minDistance);
         }
     }
     return $freq;
 }
开发者ID:BackupTheBerlios,项目名称:openpublisher-svn,代码行数:60,代码来源:Phrase.php

示例4: _nonConjunctionScore

 /**
  * Score calculator for non conjunction queries (not all subqueries are required)
  *
  * @param integer $docId
  * @param Zend_Search_Lucene $reader
  * @return float
  */
 public function _nonConjunctionScore($docId, $reader)
 {
     if ($this->_coord === null) {
         $this->_coord = array();
         $maxCoord = 0;
         foreach ($this->_signs as $sign) {
             if ($sign !== false) {
                 $maxCoord++;
             }
         }
         for ($count = 0; $count <= $maxCoord; $count++) {
             $this->_coord[$count] = $reader->getSimilarity()->coord($count, $maxCoord);
         }
     }
     $score = 0;
     $matchedSubqueries = 0;
     foreach ($this->_subqueries as $subqueryId => $subquery) {
         $subscore = $subquery->score($docId, $reader);
         // Prohibited
         if ($this->_signs[$subqueryId] === false && $subscore != 0) {
             return 0;
         }
         // is required, but doen't match
         if ($this->_signs[$subqueryId] === true && $subscore == 0) {
             return 0;
         }
         if ($subscore != 0) {
             $matchedSubqueries++;
             $score += $subscore;
         }
     }
     return $score * $this->_coord[$matchedSubqueries];
 }
开发者ID:BackupTheBerlios,项目名称:openpublisher-svn,代码行数:40,代码来源:Boolean.php

示例5: score

 /**
  * Score specified document
  *
  * @param integer $docId
  * @param Zend_Search_Lucene $reader
  * @return float
  */
 public function score($docId, $reader)
 {
     if (isset($this->_docVector[$docId])) {
         return $reader->getSimilarity()->tf(count($this->_termPositions[$docId])) * $this->_weight->getValue() * $reader->norm($docId, $this->_term->field) * $this->getBoost();
     } else {
         return 0;
     }
 }
开发者ID:5haman,项目名称:knowledgetree,代码行数:15,代码来源:Term.php


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