Ids.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace Elastica\Query;
  3. /**
  4. * Ids Query.
  5. *
  6. * @author Lee Parker
  7. * @author Nicolas Ruflin <spam@ruflin.com>
  8. * @author Tim Rupp
  9. *
  10. * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-ids-query.html
  11. */
  12. class Ids extends AbstractQuery
  13. {
  14. /**
  15. * Creates filter object.
  16. *
  17. * @param array $ids List of ids
  18. */
  19. public function __construct(array $ids = [])
  20. {
  21. $this->setIds($ids);
  22. }
  23. /**
  24. * Adds one more filter to the and filter.
  25. *
  26. * @param string $id Adds id to filter
  27. *
  28. * @return $this
  29. */
  30. public function addId($id)
  31. {
  32. $this->_params['values'][] = $id;
  33. return $this;
  34. }
  35. /**
  36. * Sets the ids to filter.
  37. *
  38. * @param array|string $ids List of ids
  39. *
  40. * @return $this
  41. */
  42. public function setIds($ids)
  43. {
  44. if (is_array($ids)) {
  45. $this->_params['values'] = $ids;
  46. } else {
  47. $this->_params['values'] = [$ids];
  48. }
  49. return $this;
  50. }
  51. /**
  52. * Converts filter to array.
  53. *
  54. * @see \Elastica\Query\AbstractQuery::toArray()
  55. *
  56. * @return array Query array
  57. */
  58. public function toArray()
  59. {
  60. return ['ids' => $this->_params];
  61. }
  62. }