1<?php
2
3namespace Elastica\Query;
4
5use Elastica\Exception\InvalidException;
6
7/**
8 * DisMax query.
9 *
10 * @author Hung Tran <oohnoitz@gmail.com>
11 *
12 * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-dis-max-query.html
13 */
14class DisMax extends AbstractQuery
15{
16    /**
17     * Adds a query to the current object.
18     *
19     * @param AbstractQuery|array $args Query
20     *
21     * @throws InvalidException If not valid query
22     *
23     * @return $this
24     */
25    public function addQuery($args): self
26    {
27        if (!\is_array($args) && !($args instanceof AbstractQuery)) {
28            throw new InvalidException('Invalid parameter. Has to be array or instance of Elastica\Query\AbstractQuery');
29        }
30
31        return $this->addParam('queries', $args);
32    }
33
34    /**
35     * Set boost.
36     *
37     * @return $this
38     */
39    public function setBoost(float $boost): self
40    {
41        return $this->setParam('boost', $boost);
42    }
43
44    /**
45     * Sets tie breaker to multiplier value to balance the scores between lower and higher scoring fields.
46     *
47     * If not set, defaults to 0.0
48     *
49     * @return $this
50     */
51    public function setTieBreaker(float $tieBreaker = 0.0): self
52    {
53        return $this->setParam('tie_breaker', $tieBreaker);
54    }
55}
56