1<?php
2
3namespace Elastica\Query;
4
5/**
6 * Term query.
7 *
8 * @author Nicolas Ruflin <spam@ruflin.com>
9 *
10 * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-term-query.html
11 */
12class Term extends AbstractQuery
13{
14    /**
15     * @param array $term Calls setTerm with the given $term array
16     */
17    public function __construct(array $term = [])
18    {
19        $this->setRawTerm($term);
20    }
21
22    /**
23     * Set term can be used instead of addTerm if some more special
24     * values for a term have to be set.
25     *
26     * @param array $term Term array
27     *
28     * @return $this
29     */
30    public function setRawTerm(array $term): self
31    {
32        return $this->setParams($term);
33    }
34
35    /**
36     * Adds a term to the term query.
37     *
38     * @param string                $key   Key to query
39     * @param bool|float|int|string $value Values(s) for the query
40     * @param float                 $boost OPTIONAL Boost value (default = 1.0)
41     *
42     * @return $this
43     */
44    public function setTerm(string $key, $value, float $boost = 1.0): self
45    {
46        return $this->setRawTerm([$key => ['value' => $value, 'boost' => $boost]]);
47    }
48}
49