DisMax.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace Elastica\Query;
  3. use Elastica\Exception\InvalidException;
  4. /**
  5. * DisMax query.
  6. *
  7. * @author Hung Tran <oohnoitz@gmail.com>
  8. *
  9. * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-dis-max-query.html
  10. */
  11. class DisMax extends AbstractQuery
  12. {
  13. /**
  14. * Adds a query to the current object.
  15. *
  16. * @param \Elastica\Query\AbstractQuery|array $args Query
  17. *
  18. * @throws \Elastica\Exception\InvalidException If not valid query
  19. *
  20. * @return $this
  21. */
  22. public function addQuery($args)
  23. {
  24. if (!is_array($args) && !($args instanceof AbstractQuery)) {
  25. throw new InvalidException('Invalid parameter. Has to be array or instance of Elastica\Query\AbstractQuery');
  26. }
  27. return $this->addParam('queries', $args);
  28. }
  29. /**
  30. * Set boost.
  31. *
  32. * @param float $boost
  33. *
  34. * @return $this
  35. */
  36. public function setBoost($boost)
  37. {
  38. return $this->setParam('boost', $boost);
  39. }
  40. /**
  41. * Sets tie breaker to multiplier value to balance the scores between lower and higher scoring fields.
  42. *
  43. * If not set, defaults to 0.0
  44. *
  45. * @param float $tieBreaker
  46. *
  47. * @return $this
  48. */
  49. public function setTieBreaker($tieBreaker = 0.0)
  50. {
  51. return $this->setParam('tie_breaker', $tieBreaker);
  52. }
  53. }