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