PageRenderTime 31ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/library/Zend/Search/Lucene/Search/Weight/Phrase.php

https://bitbucket.org/hamidrezas/melobit
PHP | 108 lines | 26 code | 16 blank | 66 comment | 0 complexity | 3c8cb443361beb882d6f0f2345d94529 MD5 | raw file
Possible License(s): AGPL-1.0
  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: Phrase.php 24594 2012-01-05 21:27:01Z matthew $
  21. */
  22. /**
  23. * Zend_Search_Lucene_Search_Weight
  24. */
  25. require_once 'Zend/Search/Lucene/Search/Weight.php';
  26. /**
  27. * @category Zend
  28. * @package Zend_Search_Lucene
  29. * @subpackage Search
  30. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  31. * @license http://framework.zend.com/license/new-bsd New BSD License
  32. */
  33. class Zend_Search_Lucene_Search_Weight_Phrase extends Zend_Search_Lucene_Search_Weight
  34. {
  35. /**
  36. * IndexReader.
  37. *
  38. * @var Zend_Search_Lucene_Interface
  39. */
  40. private $_reader;
  41. /**
  42. * The query that this concerns.
  43. *
  44. * @var Zend_Search_Lucene_Search_Query_Phrase
  45. */
  46. private $_query;
  47. /**
  48. * Score factor
  49. *
  50. * @var float
  51. */
  52. private $_idf;
  53. /**
  54. * Zend_Search_Lucene_Search_Weight_Phrase constructor
  55. *
  56. * @param Zend_Search_Lucene_Search_Query_Phrase $query
  57. * @param Zend_Search_Lucene_Interface $reader
  58. */
  59. public function __construct(Zend_Search_Lucene_Search_Query_Phrase $query,
  60. Zend_Search_Lucene_Interface $reader)
  61. {
  62. $this->_query = $query;
  63. $this->_reader = $reader;
  64. }
  65. /**
  66. * The sum of squared weights of contained query clauses.
  67. *
  68. * @return float
  69. */
  70. public function sumOfSquaredWeights()
  71. {
  72. // compute idf
  73. $this->_idf = $this->_reader->getSimilarity()->idf($this->_query->getTerms(), $this->_reader);
  74. // compute query weight
  75. $this->_queryWeight = $this->_idf * $this->_query->getBoost();
  76. // square it
  77. return $this->_queryWeight * $this->_queryWeight;
  78. }
  79. /**
  80. * Assigns the query normalization factor to this.
  81. *
  82. * @param float $queryNorm
  83. */
  84. public function normalize($queryNorm)
  85. {
  86. $this->_queryNorm = $queryNorm;
  87. // normalize query weight
  88. $this->_queryWeight *= $queryNorm;
  89. // idf for documents
  90. $this->_value = $this->_queryWeight * $this->_idf;
  91. }
  92. }