SpanTerm.php 1.3 KB

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