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