|
1
|
|
|
<?php |
|
2
|
|
|
namespace Elastica\Query; |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* Match Phrase query. |
|
6
|
|
|
* |
|
7
|
|
|
* @author Jacques Moati <[email protected]> |
|
8
|
|
|
* @author Tobias Schultze <http://tobion.de> |
|
9
|
|
|
* |
|
10
|
|
|
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query-phrase.html |
|
11
|
|
|
*/ |
|
12
|
|
|
class MatchPhrase extends AbstractQuery |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @param string $field |
|
16
|
|
|
* @param mixed $values |
|
17
|
|
|
*/ |
|
18
|
|
|
public function __construct($field = null, $values = null) |
|
19
|
|
|
{ |
|
20
|
|
|
if ($field !== null && $values !== null) { |
|
21
|
|
|
$this->setParam($field, $values); |
|
22
|
|
|
} |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Sets a param for the message array. |
|
27
|
|
|
* |
|
28
|
|
|
* @param string $field |
|
29
|
|
|
* @param mixed $values |
|
30
|
|
|
* |
|
31
|
|
|
* @return $this |
|
32
|
|
|
*/ |
|
33
|
|
|
public function setField($field, $values) |
|
34
|
|
|
{ |
|
35
|
|
|
return $this->setParam($field, $values); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Sets a param for the given field. |
|
40
|
|
|
* |
|
41
|
|
|
* @param string $field |
|
42
|
|
|
* @param string $key |
|
43
|
|
|
* @param string $value |
|
44
|
|
|
* |
|
45
|
|
|
* @return $this |
|
46
|
|
|
*/ |
|
47
|
|
View Code Duplication |
public function setFieldParam($field, $key, $value) |
|
|
|
|
|
|
48
|
|
|
{ |
|
49
|
|
|
if (!isset($this->_params[$field])) { |
|
50
|
|
|
$this->_params[$field] = []; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
$this->_params[$field][$key] = $value; |
|
54
|
|
|
|
|
55
|
|
|
return $this; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Sets the query string. |
|
60
|
|
|
* |
|
61
|
|
|
* @param string $field |
|
62
|
|
|
* @param string $query |
|
63
|
|
|
* |
|
64
|
|
|
* @return $this |
|
65
|
|
|
*/ |
|
66
|
|
|
public function setFieldQuery($field, $query) |
|
67
|
|
|
{ |
|
68
|
|
|
return $this->setFieldParam($field, 'query', $query); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Set field analyzer. |
|
73
|
|
|
* |
|
74
|
|
|
* @param string $field |
|
75
|
|
|
* @param string $analyzer |
|
76
|
|
|
* |
|
77
|
|
|
* @return $this |
|
78
|
|
|
*/ |
|
79
|
|
|
public function setFieldAnalyzer($field, $analyzer) |
|
80
|
|
|
{ |
|
81
|
|
|
return $this->setFieldParam($field, 'analyzer', $analyzer); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* Set field boost value. |
|
86
|
|
|
* |
|
87
|
|
|
* If not set, defaults to 1.0. |
|
88
|
|
|
* |
|
89
|
|
|
* @param string $field |
|
90
|
|
|
* @param float $boost |
|
91
|
|
|
* |
|
92
|
|
|
* @return $this |
|
93
|
|
|
*/ |
|
94
|
|
|
public function setFieldBoost($field, $boost = 1.0) |
|
95
|
|
|
{ |
|
96
|
|
|
return $this->setFieldParam($field, 'boost', (float) $boost); |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.