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: Default.php 16541 2009-07-07 06:59:03Z bkarwin $
24 /** Zend_Search_Lucene_Search_Similarity */
25 require_once 'Zend/Search/Lucene/Search/Similarity.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_Similarity_Default extends Zend_Search_Lucene_Search_Similarity
39 * Implemented as '1/sqrt(numTerms)'.
41 * @param string $fieldName
42 * @param integer $numTerms
45 public function lengthNorm($fieldName, $numTerms)
51 return 1.0/sqrt($numTerms);
55 * Implemented as '1/sqrt(sumOfSquaredWeights)'.
57 * @param float $sumOfSquaredWeights
60 public function queryNorm($sumOfSquaredWeights)
62 return 1.0/sqrt($sumOfSquaredWeights);
66 * Implemented as 'sqrt(freq)'.
71 public function tf($freq)
77 * Implemented as '1/(distance + 1)'.
79 * @param integer $distance
82 public function sloppyFreq($distance)
84 return 1.0/($distance + 1);
88 * Implemented as 'log(numDocs/(docFreq+1)) + 1'.
90 * @param integer $docFreq
91 * @param integer $numDocs
94 public function idfFreq($docFreq, $numDocs)
96 return log($numDocs/(float)($docFreq+1)) + 1.0;
100 * Implemented as 'overlap/maxOverlap'.
102 * @param integer $overlap
103 * @param integer $maxOverlap
106 public function coord($overlap, $maxOverlap)
108 return $overlap/(float)$maxOverlap;