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