當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。