SimpleQueryString.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace Elastica\Query;
  3. /**
  4. * Class SimpleQueryString.
  5. *
  6. * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-simple-query-string-query.html
  7. */
  8. class SimpleQueryString extends AbstractQuery
  9. {
  10. const OPERATOR_AND = 'and';
  11. const OPERATOR_OR = 'or';
  12. /**
  13. * @param string $query
  14. * @param array $fields
  15. */
  16. public function __construct($query, array $fields = [])
  17. {
  18. $this->setQuery($query);
  19. if (count($fields)) {
  20. $this->setFields($fields);
  21. }
  22. }
  23. /**
  24. * Set the querystring for this query.
  25. *
  26. * @param string $query see ES documentation for querystring syntax
  27. *
  28. * @return $this
  29. */
  30. public function setQuery($query)
  31. {
  32. return $this->setParam('query', $query);
  33. }
  34. /**
  35. * @param string[] $fields the fields on which to perform this query. Defaults to index.query.default_field.
  36. *
  37. * @return $this
  38. */
  39. public function setFields(array $fields)
  40. {
  41. return $this->setParam('fields', $fields);
  42. }
  43. /**
  44. * Set the default operator to use if no explicit operator is defined in the query string.
  45. *
  46. * @param string $operator see OPERATOR_* constants for options
  47. *
  48. * @return $this
  49. */
  50. public function setDefaultOperator($operator)
  51. {
  52. return $this->setParam('default_operator', $operator);
  53. }
  54. /**
  55. * Set the analyzer used to analyze each term of the query.
  56. *
  57. * @param string $analyzer
  58. *
  59. * @return $this
  60. */
  61. public function setAnalyzer($analyzer)
  62. {
  63. return $this->setParam('analyzer', $analyzer);
  64. }
  65. /**
  66. * Set minimum_should_match option.
  67. *
  68. * @param int|string $minimumShouldMatch
  69. *
  70. * @return $this
  71. */
  72. public function setMinimumShouldMatch($minimumShouldMatch)
  73. {
  74. return $this->setParam('minimum_should_match', $minimumShouldMatch);
  75. }
  76. }