1<?php
2
3namespace Elastica\Query;
4
5/**
6 * Match Phrase query.
7 *
8 * @author Jacques Moati <jacques@moati.net>
9 * @author Tobias Schultze <http://tobion.de>
10 *
11 * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query-phrase.html
12 */
13class MatchPhrase extends AbstractQuery
14{
15    /**
16     * @param string $field
17     * @param mixed  $values
18     */
19    public function __construct(string $field = null, $values = null)
20    {
21        if (null !== $field && null !== $values) {
22            $this->setParam($field, $values);
23        }
24    }
25
26    /**
27     * Sets a param for the message array.
28     *
29     * @param string $field
30     * @param mixed  $values
31     *
32     * @return $this
33     */
34    public function setField(string $field, $values): self
35    {
36        return $this->setParam($field, $values);
37    }
38
39    /**
40     * Sets a param for the given field.
41     *
42     * @param string $field
43     * @param string $key
44     * @param string $value
45     *
46     * @return $this
47     */
48    public function setFieldParam(string $field, string $key, string $value): self
49    {
50        if (!isset($this->_params[$field])) {
51            $this->_params[$field] = [];
52        }
53
54        $this->_params[$field][$key] = $value;
55
56        return $this;
57    }
58
59    /**
60     * Sets the query string.
61     *
62     * @param string $field
63     * @param string $query
64     *
65     * @return $this
66     */
67    public function setFieldQuery(string $field, string $query): self
68    {
69        return $this->setFieldParam($field, 'query', $query);
70    }
71
72    /**
73     * Set field analyzer.
74     *
75     * @param string $field
76     * @param string $analyzer
77     *
78     * @return $this
79     */
80    public function setFieldAnalyzer(string $field, string $analyzer): self
81    {
82        return $this->setFieldParam($field, 'analyzer', $analyzer);
83    }
84
85    /**
86     * Set field boost value.
87     *
88     * If not set, defaults to 1.0.
89     *
90     * @param string $field
91     * @param float  $boost
92     *
93     * @return $this
94     */
95    public function setFieldBoost(string $field, float $boost = 1.0): self
96    {
97        return $this->setFieldParam($field, 'boost', $boost);
98    }
99}
100