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