Prefix.php 1.2 KB

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