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: Boolean.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_Boolean 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
61 * Zend_Search_Lucene_Search_Weight_Boolean 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->getSubqueries() as $num => $subquery) {
78 if ($signs === null || $signs[$num] === null || $signs[$num]) {
79 $this->_weights[$num] = $subquery->createWeight($reader);
86 * The weight for this query
87 * Standard Weight::$_value is not used for boolean queries
91 public function getValue()
93 return $this->_query->getBoost();
98 * The sum of squared weights of contained query clauses.
102 public function sumOfSquaredWeights()
105 foreach ($this->_weights as $weight) {
107 $sum += $weight->sumOfSquaredWeights();
110 // boost each sub-weight
111 $sum *= $this->_query->getBoost() * $this->_query->getBoost();
113 // check for empty query (like '-something -another')
122 * Assigns the query normalization factor to this.
124 * @param float $queryNorm
126 public function normalize($queryNorm)
129 $queryNorm *= $this->_query->getBoost();
131 foreach ($this->_weights as $weight) {
132 $weight->normalize($queryNorm);