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