SpanMulti.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace Elastica\Query;
  3. use Elastica\Exception\InvalidException;
  4. /**
  5. * SpanMulti query.
  6. *
  7. * @author Marek Hernik <marek.hernik@gmail.com>
  8. * @author Alessandro Chitolina <alekitto@gmail.com>
  9. *
  10. * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-span-multi-term-query.html
  11. */
  12. class SpanMulti extends AbstractSpanQuery
  13. {
  14. /**
  15. * Constructs a SpanMulti query object.
  16. *
  17. * @param \Elastica\Query\AbstractQuery|array $match OPTIONAL
  18. */
  19. public function __construct($match = null)
  20. {
  21. if (null !== $match) {
  22. $this->setMatch($match);
  23. }
  24. }
  25. /**
  26. * Set the query to be wrapped into the span multi query.
  27. *
  28. * @param \Elastica\Query\AbstractQuery|array $args Matching query
  29. *
  30. * @return $this
  31. */
  32. public function setMatch($args)
  33. {
  34. return $this->_setQuery('match', $args);
  35. }
  36. /**
  37. * Sets a query to the current object.
  38. *
  39. * @param string $type Query type
  40. * @param \Elastica\Query\AbstractQuery|array $args Query
  41. *
  42. * @throws \Elastica\Exception\InvalidException If not valid query
  43. *
  44. * @return $this
  45. */
  46. protected function _setQuery($type, $args)
  47. {
  48. if (!is_array($args) && !($args instanceof AbstractQuery)) {
  49. throw new InvalidException('Invalid parameter. Has to be array or instance of Elastica\Query\AbstractQuery');
  50. }
  51. return $this->setParam($type, $args);
  52. }
  53. }