Term.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace Elastica\Query;
  3. /**
  4. * Term query.
  5. *
  6. * @author Nicolas Ruflin <spam@ruflin.com>
  7. *
  8. * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-term-query.html
  9. */
  10. class Term extends AbstractQuery
  11. {
  12. /**
  13. * Constructs the Term query object.
  14. *
  15. * @param array $term OPTIONAL Calls setTerm with the given $term array
  16. */
  17. public function __construct(array $term = [])
  18. {
  19. $this->setRawTerm($term);
  20. }
  21. /**
  22. * Set term can be used instead of addTerm if some more special
  23. * values for a term have to be set.
  24. *
  25. * @param array $term Term array
  26. *
  27. * @return $this
  28. */
  29. public function setRawTerm(array $term)
  30. {
  31. return $this->setParams($term);
  32. }
  33. /**
  34. * Adds a term to the term query.
  35. *
  36. * @param string $key Key to query
  37. * @param string|array $value Values(s) for the query. Boost can be set with array
  38. * @param float $boost OPTIONAL Boost value (default = 1.0)
  39. *
  40. * @return $this
  41. */
  42. public function setTerm($key, $value, $boost = 1.0)
  43. {
  44. return $this->setRawTerm([$key => ['value' => $value, 'boost' => $boost]]);
  45. }
  46. }