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.
16 * @package Zend_Search_Lucene
18 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
19 * @license http://framework.zend.com/license/new-bsd New BSD License
20 * @version $Id: MultiTerm.php 16541 2009-07-07 06:59:03Z bkarwin $
24 /** Zend_Search_Lucene_Search_Weight */
25 require_once 'Zend/Search/Lucene/Search/Weight.php';
30 * @package Zend_Search_Lucene
32 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
33 * @license http://framework.zend.com/license/new-bsd New BSD License
35 class Zend_Search_Lucene_Search_Weight_MultiTerm extends Zend_Search_Lucene_Search_Weight
40 * @var Zend_Search_Lucene_Interface
45 * The query that this concerns.
47 * @var Zend_Search_Lucene_Search_Query
53 * Array of Zend_Search_Lucene_Search_Weight_Term
61 * Zend_Search_Lucene_Search_Weight_MultiTerm constructor
62 * query - the query that this concerns.
63 * reader - index reader
65 * @param Zend_Search_Lucene_Search_Query $query
66 * @param Zend_Search_Lucene_Interface $reader
68 public function __construct(Zend_Search_Lucene_Search_Query $query,
69 Zend_Search_Lucene_Interface $reader)
71 $this->_query = $query;
72 $this->_reader = $reader;
73 $this->_weights = array();
75 $signs = $query->getSigns();
77 foreach ($query->getTerms() as $id => $term) {
78 if ($signs === null || $signs[$id] === null || $signs[$id]) {
79 $this->_weights[$id] = new Zend_Search_Lucene_Search_Weight_Term($term, $query, $reader);
80 $query->setWeight($id, $this->_weights[$id]);
87 * The weight for this query
88 * Standard Weight::$_value is not used for boolean queries
92 public function getValue()
94 return $this->_query->getBoost();
99 * The sum of squared weights of contained query clauses.
103 public function sumOfSquaredWeights()
106 foreach ($this->_weights as $weight) {
108 $sum += $weight->sumOfSquaredWeights();
111 // boost each sub-weight
112 $sum *= $this->_query->getBoost() * $this->_query->getBoost();
114 // check for empty query (like '-something -another')
123 * Assigns the query normalization factor to this.
125 * @param float $queryNorm
127 public function normalize($queryNorm)
130 $queryNorm *= $this->_query->getBoost();
132 foreach ($this->_weights as $weight) {
133 $weight->normalize($queryNorm);