import
[web.mtrack] / inc / lib / Zend / Search / Lucene / Search / Weight / Term.php
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-2009 Zend Technologies USA Inc. (http://www.zend.com)
19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
20  * @version    $Id: Term.php 16541 2009-07-07 06:59:03Z bkarwin $
21  */
22
23
24 /** Zend_Search_Lucene_Search_Weight */
25 require_once 'Zend/Search/Lucene/Search/Weight.php';
26
27
28 /**
29  * @category   Zend
30  * @package    Zend_Search_Lucene
31  * @subpackage Search
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
34  */
35 class Zend_Search_Lucene_Search_Weight_Term extends Zend_Search_Lucene_Search_Weight
36 {
37     /**
38      * IndexReader.
39      *
40      * @var Zend_Search_Lucene_Interface
41      */
42     private $_reader;
43
44     /**
45      * Term
46      *
47      * @var Zend_Search_Lucene_Index_Term
48      */
49     private $_term;
50
51     /**
52      * The query that this concerns.
53      *
54      * @var Zend_Search_Lucene_Search_Query
55      */
56     private $_query;
57
58     /**
59      * Score factor
60      *
61      * @var float
62      */
63     private $_idf;
64
65     /**
66      * Query weight
67      *
68      * @var float
69      */
70     private $_queryWeight;
71
72
73     /**
74      * Zend_Search_Lucene_Search_Weight_Term constructor
75      * reader - index reader
76      *
77      * @param Zend_Search_Lucene_Index_Term   $term
78      * @param Zend_Search_Lucene_Search_Query $query
79      * @param Zend_Search_Lucene_Interface    $reader
80      */
81     public function __construct(Zend_Search_Lucene_Index_Term   $term,
82                                 Zend_Search_Lucene_Search_Query $query,
83                                 Zend_Search_Lucene_Interface    $reader)
84     {
85         $this->_term   = $term;
86         $this->_query  = $query;
87         $this->_reader = $reader;
88     }
89
90
91     /**
92      * The sum of squared weights of contained query clauses.
93      *
94      * @return float
95      */
96     public function sumOfSquaredWeights()
97     {
98         // compute idf
99         $this->_idf = $this->_reader->getSimilarity()->idf($this->_term, $this->_reader);
100
101         // compute query weight
102         $this->_queryWeight = $this->_idf * $this->_query->getBoost();
103
104         // square it
105         return $this->_queryWeight * $this->_queryWeight;
106     }
107
108
109     /**
110      * Assigns the query normalization factor to this.
111      *
112      * @param float $queryNorm
113      */
114     public function normalize($queryNorm)
115     {
116         $this->_queryNorm = $queryNorm;
117
118         // normalize query weight
119         $this->_queryWeight *= $queryNorm;
120
121         // idf for documents
122         $this->_value = $this->_queryWeight * $this->_idf;
123     }
124 }
125