Subversion-Projekte lars-tiefland.prado

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/**
3
 * Zend Framework
4
 *
5
 * LICENSE
6
 *
7
 * This source file is subject to version 1.0 of the Zend Framework
8
 * license, that is bundled with this package in the file LICENSE, and
9
 * is available through the world-wide-web at the following URL:
10
 * http://www.zend.com/license/framework/1_0.txt. If you did not receive
11
 * a copy of the Zend Framework license and are unable to obtain it
12
 * through the world-wide-web, please send a note to license@zend.com
13
 * so we can mail you a copy immediately.
14
 *
15
 * @package    Zend_Search_Lucene
16
 * @subpackage Search
17
 * @copyright  Copyright (c) 2005-2006 Zend Technologies USA Inc. (http://www.zend.com)
18
 * @license    http://www.zend.com/license/framework/1_0.txt Zend Framework License version 1.0
19
 */
20
 
21
 
22
/** Zend_Search_Lucene_Search_Weight */
23
require_once 'Zend/Search/Lucene/Search/Weight.php';
24
 
25
 
26
/**
27
 * @package    Zend_Search_Lucene
28
 * @subpackage Search
29
 * @copyright  Copyright (c) 2005-2006 Zend Technologies USA Inc. (http://www.zend.com)
30
 * @license    http://www.zend.com/license/framework/1_0.txt Zend Framework License version 1.0
31
 */
32
class Zend_Search_Lucene_Search_Weight_Term extends Zend_Search_Lucene_Search_Weight
33
{
34
    /**
35
     * IndexReader.
36
     *
37
     * @var Zend_Search_Lucene
38
     */
39
    private $_reader;
40
 
41
    /**
42
     * Term
43
     *
44
     * @var Zend_Search_Lucene_Index_Term
45
     */
46
    private $_term;
47
 
48
    /**
49
     * The query that this concerns.
50
     *
51
     * @var Zend_Search_Lucene_Search_Query
52
     */
53
    private $_query;
54
 
55
    /**
56
     * Weight value
57
     *
58
     * @var float
59
     */
60
    private $_value;
61
 
62
    /**
63
     * Score factor
64
     *
65
     * @var float
66
     */
67
    private $_idf;
68
 
69
    /**
70
     * Normalization factor
71
     *
72
     * @var float
73
     */
74
    private $_queryNorm;
75
 
76
 
77
    /**
78
     * Query weight
79
     *
80
     * @var float
81
     */
82
    private $_queryWeight;
83
 
84
 
85
    /**
86
     * Zend_Search_Lucene_Search_Weight_Term constructor
87
     * reader - index reader
88
     *
89
     * @param Zend_Search_Lucene $reader
90
     */
91
    public function __construct($term, $query, $reader)
92
    {
93
        $this->_term   = $term;
94
        $this->_query  = $query;
95
        $this->_reader = $reader;
96
    }
97
 
98
 
99
    /**
100
     * The weight for this query
101
     *
102
     * @return float
103
     */
104
    public function getValue()
105
    {
106
        return $this->_value;
107
    }
108
 
109
 
110
    /**
111
     * The sum of squared weights of contained query clauses.
112
     *
113
     * @return float
114
     */
115
    public function sumOfSquaredWeights()
116
    {
117
        // compute idf
118
        $this->_idf = $this->_reader->getSimilarity()->idf($this->_term, $this->_reader);
119
 
120
        // compute query weight
121
        $this->_queryWeight = $this->_idf * $this->_query->getBoost();
122
 
123
        // square it
124
        return $this->_queryWeight * $this->_queryWeight;
125
    }
126
 
127
 
128
    /**
129
     * Assigns the query normalization factor to this.
130
     *
131
     * @param float $queryNorm
132
     */
133
    public function normalize($queryNorm)
134
    {
135
        $this->_queryNorm = $queryNorm;
136
 
137
        // normalize query weight
138
        $this->_queryWeight *= $queryNorm;
139
 
140
        // idf for documents
141
        $this->_value = $this->_queryWeight * $this->_idf;
142
    }
143
}
144