@@ -56,30 +56,35 @@ public function setFilter(AbstractFilter $filter)
56
56
* @param string $functionType valid values are DECAY_* constants and script_score
57
57
* @param array|float $functionParams the body of the function. See documentation for proper syntax.
58
58
* @param AbstractFilter $filter optional filter to apply to the function
59
+ * @param float $weight function weight
59
60
* @return \Elastica\Query\FunctionScore
60
61
*/
61
- public function addFunction ($ functionType , $ functionParams , AbstractFilter $ filter = null )
62
+ public function addFunction ($ functionType , $ functionParams , AbstractFilter $ filter = null , $ weight = null )
62
63
{
63
64
$ function = array (
64
65
$ functionType => $ functionParams ,
65
66
);
66
67
if (!is_null ($ filter )) {
67
68
$ function ['filter ' ] = $ filter ->toArray ();
68
69
}
69
- $ this ->_functions [] = $ function ;
70
+ if ($ weight !== null ) {
71
+ $ function ['weight ' ] = $ weight ;
72
+ }
70
73
74
+ $ this ->_functions [] = $ function ;
71
75
return $ this ;
72
76
}
73
77
74
78
/**
75
79
* Add a script_score function to the query
76
80
* @param Script $script a Script object
77
81
* @param AbstractFilter $filter an optional filter to apply to the function
82
+ * @param float $weight the weight of the function
78
83
* @return \Elastica\Query\FunctionScore
79
84
*/
80
- public function addScriptScoreFunction (Script $ script , AbstractFilter $ filter = null )
85
+ public function addScriptScoreFunction (Script $ script , AbstractFilter $ filter = null , $ weight = null )
81
86
{
82
- return $ this ->addFunction ('script_score ' , $ script ->toArray (), $ filter );
87
+ return $ this ->addFunction ('script_score ' , $ script ->toArray (), $ filter, $ weight );
83
88
}
84
89
85
90
/**
@@ -91,12 +96,20 @@ public function addScriptScoreFunction(Script $script, AbstractFilter $filter =
91
96
* @param string $offset If defined, this function will only be computed for documents with a distance from the origin greater than this value
92
97
* @param float $decay optionally defines how documents are scored at the distance given by the $scale parameter
93
98
* @param float $scaleWeight optional factor by which to multiply the score at the value provided by the $scale parameter
99
+ * @param float $weight optional factor by which to multiply the score at the value provided by the $scale parameter
94
100
* @param AbstractFilter $filter a filter associated with this function
95
101
* @return \Elastica\Query\FunctionScore
96
102
*/
97
- public function addDecayFunction ($ function , $ field , $ origin , $ scale , $ offset = null , $ decay = null , $ scaleWeight = null ,
98
- AbstractFilter $ filter = null )
99
- {
103
+ public function addDecayFunction (
104
+ $ function ,
105
+ $ field ,
106
+ $ origin ,
107
+ $ scale ,
108
+ $ offset = null ,
109
+ $ decay = null ,
110
+ $ weight = null ,
111
+ AbstractFilter $ filter = null
112
+ ) {
100
113
$ functionParams = array (
101
114
$ field => array (
102
115
'origin ' => $ origin ,
@@ -109,32 +122,44 @@ public function addDecayFunction($function, $field, $origin, $scale, $offset = n
109
122
if (!is_null ($ decay )) {
110
123
$ functionParams [$ field ]['decay ' ] = (float ) $ decay ;
111
124
}
112
- if (!is_null ($ scaleWeight )) {
113
- $ functionParams [$ field ]['scale_weight ' ] = (float ) $ scaleWeight ;
114
- }
115
125
116
- return $ this ->addFunction ($ function , $ functionParams , $ filter );
126
+ return $ this ->addFunction ($ function , $ functionParams , $ filter, $ weight );
117
127
}
118
128
119
129
/**
120
130
* Add a boost_factor function to the query
131
+ *
121
132
* @param float $boostFactor the boost factor value
122
133
* @param AbstractFilter $filter a filter associated with this function
134
+ *
135
+ * @return void
136
+ * @deprecated
123
137
*/
124
138
public function addBoostFactorFunction ($ boostFactor , AbstractFilter $ filter = null )
125
139
{
126
- $ this ->addFunction ('boost_factor ' , $ boostFactor , $ filter );
140
+ $ this ->addWeightFunction ($ boostFactor , $ filter );
141
+ }
142
+
143
+ /**
144
+ * @param float $weight the weight of the function
145
+ * @param AbstractFilter $filter a filter associated with this function
146
+ *
147
+ * @return void
148
+ */
149
+ public function addWeightFunction ($ weight , AbstractFilter $ filter = null )
150
+ {
151
+ $ this ->addFunction ('weight ' , $ weight , $ filter );
127
152
}
128
153
129
154
/**
130
155
* Add a random_score function to the query
131
156
* @param number $seed the seed value
132
157
* @param AbstractFilter $filter a filter associated with this function
133
- * @param float $boost an optional boost value associated with this function
158
+ * @param float $weight an optional boost value associated with this function
134
159
*/
135
- public function addRandomScoreFunction ($ seed , AbstractFilter $ filter = null , $ boost = null )
160
+ public function addRandomScoreFunction ($ seed , AbstractFilter $ filter = null , $ weight = null )
136
161
{
137
- $ this ->addFunction ('random_score ' , array ('seed ' => $ seed ), $ filter , $ boost );
162
+ $ this ->addFunction ('random_score ' , array ('seed ' => $ seed ), $ filter , $ weight );
138
163
}
139
164
140
165
/**
0 commit comments