/zf/library/Zend/Search/Lucene/Search/QueryEntry/Phrase.php

http://github.com/eryx/php-framework-benchmark · PHP · 116 lines · 35 code · 14 blank · 67 comment · 2 complexity · 89c8b340566b96c87d7b2482ca1b9229 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-2011 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 23775 2011-03-01 17:25:24Z ralph $
  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-2011 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_Phrase extends Zend_Search_Lucene_Search_QueryEntry
  32. {
  33. /**
  34. * Phrase value
  35. *
  36. * @var string
  37. */
  38. private $_phrase;
  39. /**
  40. * Field
  41. *
  42. * @var string|null
  43. */
  44. private $_field;
  45. /**
  46. * Proximity phrase query
  47. *
  48. * @var boolean
  49. */
  50. private $_proximityQuery = false;
  51. /**
  52. * Words distance, used for proximiti queries
  53. *
  54. * @var integer
  55. */
  56. private $_wordsDistance = 0;
  57. /**
  58. * Object constractor
  59. *
  60. * @param string $phrase
  61. * @param string $field
  62. */
  63. public function __construct($phrase, $field)
  64. {
  65. $this->_phrase = $phrase;
  66. $this->_field = $field;
  67. }
  68. /**
  69. * Process modifier ('~')
  70. *
  71. * @param mixed $parameter
  72. */
  73. public function processFuzzyProximityModifier($parameter = null)
  74. {
  75. $this->_proximityQuery = true;
  76. if ($parameter !== null) {
  77. $this->_wordsDistance = $parameter;
  78. }
  79. }
  80. /**
  81. * Transform entry to a subquery
  82. *
  83. * @param string $encoding
  84. * @return Zend_Search_Lucene_Search_Query
  85. * @throws Zend_Search_Lucene_Search_QueryParserException
  86. */
  87. public function getQuery($encoding)
  88. {
  89. /** Zend_Search_Lucene_Search_Query_Preprocessing_Phrase */
  90. require_once 'Zend/Search/Lucene/Search/Query/Preprocessing/Phrase.php';
  91. $query = new Zend_Search_Lucene_Search_Query_Preprocessing_Phrase($this->_phrase,
  92. $encoding,
  93. ($this->_field !== null)?
  94. iconv($encoding, 'UTF-8', $this->_field) :
  95. null);
  96. if ($this->_proximityQuery) {
  97. $query->setSlop($this->_wordsDistance);
  98. }
  99. $query->setBoost($this->_boost);
  100. return $query;
  101. }
  102. }