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     * @param float $boost
38     *
39     * @return $this
40     */
41    public function setBoost(float $boost): self
42    {
43        return $this->setParam('boost', $boost);
44    }
45
46    /**
47     * Sets tie breaker to multiplier value to balance the scores between lower and higher scoring fields.
48     *
49     * If not set, defaults to 0.0
50     *
51     * @param float $tieBreaker
52     *
53     * @return $this
54     */
55    public function setTieBreaker(float $tieBreaker = 0.0): self
56    {
57        return $this->setParam('tie_breaker', $tieBreaker);
58    }
59}
60