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     * @param array $term Calls setRawTerm with the given $term array
17     */
18    public function __construct(array $term = [])
19    {
20        $this->setRawTerm($term);
21    }
22
23    /**
24     * Set term can be used instead of setTerm if some more special
25     * values for a term have to be set.
26     *
27     * @param array $term Term array
28     *
29     * @return $this
30     */
31    public function setRawTerm(array $term): self
32    {
33        return $this->setParams($term);
34    }
35
36    /**
37     * Adds a term to the term query.
38     *
39     * @param string       $key   Key to query
40     * @param array|string $value Values(s) for the query. Boost can be set with array
41     * @param float        $boost OPTIONAL Boost value (default = 1.0)
42     *
43     * @return $this
44     */
45    public function setTerm(string $key, $value, float $boost = 1.0): self
46    {
47        return $this->setRawTerm([$key => ['value' => $value, 'boost' => $boost]]);
48    }
49}
50