1<?php
2
3namespace Elastica\Query;
4
5/**
6 * Multi Match.
7 *
8 * @author Rodolfo Adhenawer Campagnoli Moraes <adhenawer@gmail.com>
9 * @author Wong Wing Lun <luiges90@gmail.com>
10 * @author Tristan Maindron <tmaindron@gmail.com>
11 *
12 * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-multi-match-query.html
13 */
14class MultiMatch extends AbstractQuery
15{
16    public const TYPE_BEST_FIELDS = 'best_fields';
17    public const TYPE_MOST_FIELDS = 'most_fields';
18    public const TYPE_CROSS_FIELDS = 'cross_fields';
19    public const TYPE_PHRASE = 'phrase';
20    public const TYPE_PHRASE_PREFIX = 'phrase_prefix';
21
22    public const OPERATOR_OR = 'or';
23    public const OPERATOR_AND = 'and';
24
25    public const ZERO_TERM_NONE = 'none';
26    public const ZERO_TERM_ALL = 'all';
27
28    public const FUZZINESS_AUTO = 'AUTO';
29
30    /**
31     * Sets the query.
32     *
33     * @param string $query Query
34     *
35     * @return $this
36     */
37    public function setQuery(string $query = ''): self
38    {
39        return $this->setParam('query', $query);
40    }
41
42    /**
43     * Sets Fields to be used in the query.
44     *
45     * @param array $fields Fields
46     *
47     * @return $this
48     */
49    public function setFields(array $fields = []): self
50    {
51        return $this->setParam('fields', $fields);
52    }
53
54    /**
55     * Sets use dis max indicating to either create a dis_max query or a bool query.
56     *
57     * If not set, defaults to true.
58     *
59     * @return $this
60     */
61    public function setUseDisMax(bool $useDisMax = true): self
62    {
63        return $this->setParam('use_dis_max', $useDisMax);
64    }
65
66    /**
67     * Sets tie breaker to multiplier value to balance the scores between lower and higher scoring fields.
68     *
69     * If not set, defaults to 0.0.
70     *
71     * @return $this
72     */
73    public function setTieBreaker(float $tieBreaker = 0.0): self
74    {
75        return $this->setParam('tie_breaker', $tieBreaker);
76    }
77
78    /**
79     * Sets operator for Match Query.
80     *
81     * If not set, defaults to 'or'
82     *
83     * @return $this
84     */
85    public function setOperator(string $operator = self::OPERATOR_OR): self
86    {
87        return $this->setParam('operator', $operator);
88    }
89
90    /**
91     * Set field minimum should match for Match Query.
92     *
93     * @param mixed $minimumShouldMatch
94     *
95     * @return $this
96     */
97    public function setMinimumShouldMatch($minimumShouldMatch): self
98    {
99        return $this->setParam('minimum_should_match', $minimumShouldMatch);
100    }
101
102    /**
103     * Set zero terms query for Match Query.
104     *
105     * If not set, default to 'none'
106     *
107     * @return $this
108     */
109    public function setZeroTermsQuery(string $zeroTermQuery = self::ZERO_TERM_NONE): self
110    {
111        return $this->setParam('zero_terms_query', $zeroTermQuery);
112    }
113
114    /**
115     * Set cutoff frequency for Match Query.
116     *
117     * @return $this
118     *
119     * @deprecated since 7.1.3
120     */
121    public function setCutoffFrequency(float $cutoffFrequency): self
122    {
123        \trigger_deprecation('ruflin/elastica', '7.1.3', 'The "%s()" method is deprecated. It will be removed in 8.0.', __METHOD__);
124
125        return $this->setParam('cutoff_frequency', $cutoffFrequency);
126    }
127
128    /**
129     * Set type.
130     *
131     * @return $this
132     */
133    public function setType(string $type): self
134    {
135        return $this->setParam('type', $type);
136    }
137
138    /**
139     * Set fuzziness.
140     *
141     * @param float|string $fuzziness
142     *
143     * @return $this
144     */
145    public function setFuzziness($fuzziness): self
146    {
147        return $this->setParam('fuzziness', $fuzziness);
148    }
149
150    /**
151     * Set prefix length.
152     *
153     * @return $this
154     */
155    public function setPrefixLength(int $prefixLength): self
156    {
157        return $this->setParam('prefix_length', $prefixLength);
158    }
159
160    /**
161     * Set max expansions.
162     *
163     * @return $this
164     */
165    public function setMaxExpansions(int $maxExpansions): self
166    {
167        return $this->setParam('max_expansions', $maxExpansions);
168    }
169
170    /**
171     * Set analyzer.
172     *
173     * @return $this
174     */
175    public function setAnalyzer(string $analyzer): self
176    {
177        return $this->setParam('analyzer', $analyzer);
178    }
179}
180