1<?php
2
3namespace Elastica\Query;
4
5use Elastica\Exception\InvalidException;
6
7/**
8 * SpanMulti query.
9 *
10 * @author Marek Hernik <marek.hernik@gmail.com>
11 * @author Alessandro Chitolina <alekitto@gmail.com>
12 *
13 * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-span-multi-term-query.html
14 */
15class SpanMulti extends AbstractSpanQuery
16{
17    /**
18     * @param AbstractQuery|array $match
19     */
20    public function __construct($match = null)
21    {
22        if (null !== $match) {
23            $this->setMatch($match);
24        }
25    }
26
27    /**
28     * Set the query to be wrapped into the span multi query.
29     *
30     * @param AbstractQuery|array $args Matching query
31     *
32     * @return $this
33     */
34    public function setMatch($args): self
35    {
36        return $this->_setQuery('match', $args);
37    }
38
39    /**
40     * Sets a query to the current object.
41     *
42     * @param string              $type Query type
43     * @param AbstractQuery|array $args Query
44     *
45     * @throws InvalidException If not valid query
46     *
47     * @return $this
48     */
49    protected function _setQuery(string $type, $args): self
50    {
51        if (!\is_array($args) && !($args instanceof AbstractQuery)) {
52            throw new InvalidException('Invalid parameter. Has to be array or instance of Elastica\Query\AbstractQuery');
53        }
54
55        return $this->setParam($type, $args);
56    }
57}
58