MultiMatch.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <?php
  2. namespace Elastica\Query;
  3. /**
  4. * Multi Match.
  5. *
  6. * @author Rodolfo Adhenawer Campagnoli Moraes <adhenawer@gmail.com>
  7. * @author Wong Wing Lun <luiges90@gmail.com>
  8. * @author Tristan Maindron <tmaindron@gmail.com>
  9. *
  10. * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-multi-match-query.html
  11. */
  12. class MultiMatch extends AbstractQuery
  13. {
  14. const TYPE_BEST_FIELDS = 'best_fields';
  15. const TYPE_MOST_FIELDS = 'most_fields';
  16. const TYPE_CROSS_FIELDS = 'cross_fields';
  17. const TYPE_PHRASE = 'phrase';
  18. const TYPE_PHRASE_PREFIX = 'phrase_prefix';
  19. const OPERATOR_OR = 'or';
  20. const OPERATOR_AND = 'and';
  21. const ZERO_TERM_NONE = 'none';
  22. const ZERO_TERM_ALL = 'all';
  23. const FUZZINESS_AUTO = 'AUTO';
  24. /**
  25. * Sets the query.
  26. *
  27. * @param string $query Query
  28. *
  29. * @return $this
  30. */
  31. public function setQuery($query = '')
  32. {
  33. return $this->setParam('query', $query);
  34. }
  35. /**
  36. * Sets Fields to be used in the query.
  37. *
  38. * @param array $fields Fields
  39. *
  40. * @return $this
  41. */
  42. public function setFields($fields = [])
  43. {
  44. return $this->setParam('fields', $fields);
  45. }
  46. /**
  47. * Sets use dis max indicating to either create a dis_max query or a bool query.
  48. *
  49. * If not set, defaults to true.
  50. *
  51. * @param bool $useDisMax
  52. *
  53. * @return $this
  54. */
  55. public function setUseDisMax($useDisMax = true)
  56. {
  57. return $this->setParam('use_dis_max', $useDisMax);
  58. }
  59. /**
  60. * Sets tie breaker to multiplier value to balance the scores between lower and higher scoring fields.
  61. *
  62. * If not set, defaults to 0.0.
  63. *
  64. * @param float $tieBreaker
  65. *
  66. * @return $this
  67. */
  68. public function setTieBreaker($tieBreaker = 0.0)
  69. {
  70. return $this->setParam('tie_breaker', $tieBreaker);
  71. }
  72. /**
  73. * Sets operator for Match Query.
  74. *
  75. * If not set, defaults to 'or'
  76. *
  77. * @param string $operator
  78. *
  79. * @return $this
  80. */
  81. public function setOperator($operator = self::OPERATOR_OR)
  82. {
  83. return $this->setParam('operator', $operator);
  84. }
  85. /**
  86. * Set field minimum should match for Match Query.
  87. *
  88. * @param mixed $minimumShouldMatch
  89. *
  90. * @return $this
  91. */
  92. public function setMinimumShouldMatch($minimumShouldMatch)
  93. {
  94. return $this->setParam('minimum_should_match', $minimumShouldMatch);
  95. }
  96. /**
  97. * Set zero terms query for Match Query.
  98. *
  99. * If not set, default to 'none'
  100. *
  101. * @param string $zeroTermQuery
  102. *
  103. * @return $this
  104. */
  105. public function setZeroTermsQuery($zeroTermQuery = self::ZERO_TERM_NONE)
  106. {
  107. return $this->setParam('zero_terms_query', $zeroTermQuery);
  108. }
  109. /**
  110. * Set cutoff frequency for Match Query.
  111. *
  112. * @param float $cutoffFrequency
  113. *
  114. * @return $this
  115. */
  116. public function setCutoffFrequency($cutoffFrequency)
  117. {
  118. return $this->setParam('cutoff_frequency', $cutoffFrequency);
  119. }
  120. /**
  121. * Set type.
  122. *
  123. * @param string $type
  124. *
  125. * @return $this
  126. */
  127. public function setType($type)
  128. {
  129. return $this->setParam('type', $type);
  130. }
  131. /**
  132. * Set fuzziness.
  133. *
  134. * @param float|string $fuzziness
  135. *
  136. * @return $this
  137. */
  138. public function setFuzziness($fuzziness)
  139. {
  140. return $this->setParam('fuzziness', $fuzziness);
  141. }
  142. /**
  143. * Set prefix length.
  144. *
  145. * @param int $prefixLength
  146. *
  147. * @return $this
  148. */
  149. public function setPrefixLength($prefixLength)
  150. {
  151. return $this->setParam('prefix_length', (int) $prefixLength);
  152. }
  153. /**
  154. * Set max expansions.
  155. *
  156. * @param int $maxExpansions
  157. *
  158. * @return $this
  159. */
  160. public function setMaxExpansions($maxExpansions)
  161. {
  162. return $this->setParam('max_expansions', (int) $maxExpansions);
  163. }
  164. /**
  165. * Set analyzer.
  166. *
  167. * @param string $analyzer
  168. *
  169. * @return $this
  170. */
  171. public function setAnalyzer($analyzer)
  172. {
  173. return $this->setParam('analyzer', $analyzer);
  174. }
  175. }