[ Index ]

PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008]

title

Body

[close]

/search/Zend/Search/Lucene/Search/Weight/ -> Phrase.php (source)

   1  <?php
   2  /**
   3   * Zend Framework
   4   *
   5   * LICENSE
   6   *
   7   * This source file is subject to the new BSD license that is bundled
   8   * with this package in the file LICENSE.txt.
   9   * It is also available through the world-wide-web at this URL:
  10   * http://framework.zend.com/license/new-bsd
  11   * If you did not receive a copy of the license and are unable to
  12   * obtain it through the world-wide-web, please send an email
  13   * to license@zend.com so we can send you a copy immediately.
  14   *
  15   * @category   Zend
  16   * @package    Zend_Search_Lucene
  17   * @subpackage Search
  18   * @copyright  Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
  19   * @license    http://framework.zend.com/license/new-bsd     New BSD License
  20   */
  21  
  22  
  23  /**
  24   * Zend_Search_Lucene_Search_Weight
  25   */
  26  require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Search/Weight.php';
  27  
  28  
  29  /**
  30   * @category   Zend
  31   * @package    Zend_Search_Lucene
  32   * @subpackage Search
  33   * @copyright  Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
  34   * @license    http://framework.zend.com/license/new-bsd     New BSD License
  35   */
  36  class Zend_Search_Lucene_Search_Weight_Phrase extends Zend_Search_Lucene_Search_Weight
  37  {
  38      /**
  39       * IndexReader.
  40       *
  41       * @var Zend_Search_Lucene_Interface
  42       */
  43      private $_reader;
  44  
  45      /**
  46       * The query that this concerns.
  47       *
  48       * @var Zend_Search_Lucene_Search_Query_Phrase
  49       */
  50      private $_query;
  51  
  52      /**
  53       * Score factor
  54       *
  55       * @var float
  56       */
  57      private $_idf;
  58  
  59      /**
  60       * Zend_Search_Lucene_Search_Weight_Phrase constructor
  61       *
  62       * @param Zend_Search_Lucene_Search_Query_Phrase $query
  63       * @param Zend_Search_Lucene_Interface           $reader
  64       */
  65      public function __construct(Zend_Search_Lucene_Search_Query_Phrase $query,
  66                                  Zend_Search_Lucene_Interface           $reader)
  67      {
  68          $this->_query  = $query;
  69          $this->_reader = $reader;
  70      }
  71  
  72      /**
  73       * The sum of squared weights of contained query clauses.
  74       *
  75       * @return float
  76       */
  77      public function sumOfSquaredWeights()
  78      {
  79          // compute idf
  80          $this->_idf = $this->_reader->getSimilarity()->idf($this->_query->getTerms(), $this->_reader);
  81  
  82          // compute query weight
  83          $this->_queryWeight = $this->_idf * $this->_query->getBoost();
  84  
  85          // square it
  86          return $this->_queryWeight * $this->_queryWeight;
  87      }
  88  
  89  
  90      /**
  91       * Assigns the query normalization factor to this.
  92       *
  93       * @param float $queryNorm
  94       */
  95      public function normalize($queryNorm)
  96      {
  97          $this->_queryNorm = $queryNorm;
  98  
  99          // normalize query weight
 100          $this->_queryWeight *= $queryNorm;
 101  
 102          // idf for documents
 103          $this->_value = $this->_queryWeight * $this->_idf;
 104      }
 105  }
 106  
 107  


Generated: Wed Jan 14 11:33:29 2009 Cross-referenced by PHPXref 0.7