Term.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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$
  21. */
  22. /** Zend_Search_Lucene_Search_QueryEntry */
  23. require_once 'Zend/Search/Lucene/Search/QueryEntry.php';
  24. /**
  25. * @category Zend
  26. * @package Zend_Search_Lucene
  27. * @subpackage Search
  28. * @copyright Copyright (c) 2005-2009 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_QueryEntry_Term extends Zend_Search_Lucene_Search_QueryEntry
  32. {
  33. /**
  34. * Term value
  35. *
  36. * @var string
  37. */
  38. private $_term;
  39. /**
  40. * Field
  41. *
  42. * @var string|null
  43. */
  44. private $_field;
  45. /**
  46. * Fuzzy search query
  47. *
  48. * @var boolean
  49. */
  50. private $_fuzzyQuery = false;
  51. /**
  52. * Similarity
  53. *
  54. * @var float
  55. */
  56. private $_similarity = 1.;
  57. /**
  58. * Object constractor
  59. *
  60. * @param string $term
  61. * @param string $field
  62. */
  63. public function __construct($term, $field)
  64. {
  65. $this->_term = $term;
  66. $this->_field = $field;
  67. }
  68. /**
  69. * Process modifier ('~')
  70. *
  71. * @param mixed $parameter
  72. */
  73. public function processFuzzyProximityModifier($parameter = null)
  74. {
  75. $this->_fuzzyQuery = true;
  76. if ($parameter !== null) {
  77. $this->_similarity = $parameter;
  78. } else {
  79. /** Zend_Search_Lucene_Search_Query_Fuzzy */
  80. require_once 'Zend/Search/Lucene/Search/Query/Fuzzy.php';
  81. $this->_similarity = Zend_Search_Lucene_Search_Query_Fuzzy::DEFAULT_MIN_SIMILARITY;
  82. }
  83. }
  84. /**
  85. * Transform entry to a subquery
  86. *
  87. * @param string $encoding
  88. * @return Zend_Search_Lucene_Search_Query
  89. * @throws Zend_Search_Lucene_Search_QueryParserException
  90. */
  91. public function getQuery($encoding)
  92. {
  93. if ($this->_fuzzyQuery) {
  94. /** Zend_Search_Lucene_Search_Query_Preprocessing_Fuzzy */
  95. require_once 'Zend/Search/Lucene/Search/Query/Preprocessing/Fuzzy.php';
  96. $query = new Zend_Search_Lucene_Search_Query_Preprocessing_Fuzzy($this->_term,
  97. $encoding,
  98. ($this->_field !== null)?
  99. iconv($encoding, 'UTF-8', $this->_field) :
  100. null,
  101. $this->_similarity
  102. );
  103. $query->setBoost($this->_boost);
  104. return $query;
  105. }
  106. /** Zend_Search_Lucene_Search_Query_Preprocessing_Term */
  107. require_once 'Zend/Search/Lucene/Search/Query/Preprocessing/Term.php';
  108. $query = new Zend_Search_Lucene_Search_Query_Preprocessing_Term($this->_term,
  109. $encoding,
  110. ($this->_field !== null)?
  111. iconv($encoding, 'UTF-8', $this->_field) :
  112. null
  113. );
  114. $query->setBoost($this->_boost);
  115. return $query;
  116. }
  117. }