PageRenderTime 43ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/Search/Lucene/Search/Similarity/Default.php

https://bitbucket.org/bigstylee/zend-framework
PHP | 110 lines | 32 code | 11 blank | 67 comment | 2 complexity | 1f2d8076916416196e2040ff2adbaad3 MD5 | raw file
  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-2012 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 24593 2012-01-05 20:35:02Z matthew $
  21. */
  22. /** Zend_Search_Lucene_Search_Similarity */
  23. require_once 'Zend/Search/Lucene/Search/Similarity.php';
  24. /**
  25. * @category Zend
  26. * @package Zend_Search_Lucene
  27. * @subpackage Search
  28. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  29. * @license http://framework.zend.com/license/new-bsd New BSD License
  30. */
  31. class Zend_Search_Lucene_Search_Similarity_Default extends Zend_Search_Lucene_Search_Similarity
  32. {
  33. /**
  34. * Implemented as '1/sqrt(numTerms)'.
  35. *
  36. * @param string $fieldName
  37. * @param integer $numTerms
  38. * @return float
  39. */
  40. public function lengthNorm($fieldName, $numTerms)
  41. {
  42. if ($numTerms == 0) {
  43. return 1E10;
  44. }
  45. return 1.0/sqrt($numTerms);
  46. }
  47. /**
  48. * Implemented as '1/sqrt(sumOfSquaredWeights)'.
  49. *
  50. * @param float $sumOfSquaredWeights
  51. * @return float
  52. */
  53. public function queryNorm($sumOfSquaredWeights)
  54. {
  55. return 1.0/sqrt($sumOfSquaredWeights);
  56. }
  57. /**
  58. * Implemented as 'sqrt(freq)'.
  59. *
  60. * @param float $freq
  61. * @return float
  62. */
  63. public function tf($freq)
  64. {
  65. return sqrt($freq);
  66. }
  67. /**
  68. * Implemented as '1/(distance + 1)'.
  69. *
  70. * @param integer $distance
  71. * @return float
  72. */
  73. public function sloppyFreq($distance)
  74. {
  75. return 1.0/($distance + 1);
  76. }
  77. /**
  78. * Implemented as 'log(numDocs/(docFreq+1)) + 1'.
  79. *
  80. * @param integer $docFreq
  81. * @param integer $numDocs
  82. * @return float
  83. */
  84. public function idfFreq($docFreq, $numDocs)
  85. {
  86. return log($numDocs/(float)($docFreq+1)) + 1.0;
  87. }
  88. /**
  89. * Implemented as 'overlap/maxOverlap'.
  90. *
  91. * @param integer $overlap
  92. * @param integer $maxOverlap
  93. * @return float
  94. */
  95. public function coord($overlap, $maxOverlap)
  96. {
  97. return $overlap/(float)$maxOverlap;
  98. }
  99. }