| [ Index ] |
PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008] |
[Summary view] [Print] [Text view]
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 /** Zend_Search_Lucene_Search_Weight */ 24 require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Search/Weight.php'; 25 26 27 /** 28 * @category Zend 29 * @package Zend_Search_Lucene 30 * @subpackage Search 31 * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com) 32 * @license http://framework.zend.com/license/new-bsd New BSD License 33 */ 34 class Zend_Search_Lucene_Search_Weight_MultiTerm extends Zend_Search_Lucene_Search_Weight 35 { 36 /** 37 * IndexReader. 38 * 39 * @var Zend_Search_Lucene_Interface 40 */ 41 private $_reader; 42 43 /** 44 * The query that this concerns. 45 * 46 * @var Zend_Search_Lucene_Search_Query 47 */ 48 private $_query; 49 50 /** 51 * Query terms weights 52 * Array of Zend_Search_Lucene_Search_Weight_Term 53 * 54 * @var array 55 */ 56 private $_weights; 57 58 59 /** 60 * Zend_Search_Lucene_Search_Weight_MultiTerm constructor 61 * query - the query that this concerns. 62 * reader - index reader 63 * 64 * @param Zend_Search_Lucene_Search_Query $query 65 * @param Zend_Search_Lucene_Interface $reader 66 */ 67 public function __construct(Zend_Search_Lucene_Search_Query $query, 68 Zend_Search_Lucene_Interface $reader) 69 { 70 $this->_query = $query; 71 $this->_reader = $reader; 72 $this->_weights = array(); 73 74 $signs = $query->getSigns(); 75 76 foreach ($query->getTerms() as $id => $term) { 77 if ($signs === null || $signs[$id] === null || $signs[$id]) { 78 $this->_weights[$id] = new Zend_Search_Lucene_Search_Weight_Term($term, $query, $reader); 79 $query->setWeight($id, $this->_weights[$id]); 80 } 81 } 82 } 83 84 85 /** 86 * The weight for this query 87 * Standard Weight::$_value is not used for boolean queries 88 * 89 * @return float 90 */ 91 public function getValue() 92 { 93 return $this->_query->getBoost(); 94 } 95 96 97 /** 98 * The sum of squared weights of contained query clauses. 99 * 100 * @return float 101 */ 102 public function sumOfSquaredWeights() 103 { 104 $sum = 0; 105 foreach ($this->_weights as $weight) { 106 // sum sub weights 107 $sum += $weight->sumOfSquaredWeights(); 108 } 109 110 // boost each sub-weight 111 $sum *= $this->_query->getBoost() * $this->_query->getBoost(); 112 113 // check for empty query (like '-something -another') 114 if ($sum == 0) { 115 $sum = 1.0; 116 } 117 return $sum; 118 } 119 120 121 /** 122 * Assigns the query normalization factor to this. 123 * 124 * @param float $queryNorm 125 */ 126 public function normalize($queryNorm) 127 { 128 // incorporate boost 129 $queryNorm *= $this->_query->getBoost(); 130 131 foreach ($this->_weights as $weight) { 132 $weight->normalize($queryNorm); 133 } 134 } 135 } 136 137
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Jan 14 11:33:29 2009 | Cross-referenced by PHPXref 0.7 |