Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
85.71% |
6 / 7 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
CustomFieldFunctionScoreBuilder | |
85.71% |
6 / 7 |
|
50.00% |
1 / 2 |
5.07 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
append | |
66.67% |
2 / 3 |
|
0.00% |
0 / 1 |
3.33 |
1 | <?php |
2 | |
3 | namespace CirrusSearch\Search\Rescore; |
4 | |
5 | use CirrusSearch\SearchConfig; |
6 | use Elastica\Query\FunctionScore; |
7 | |
8 | /** |
9 | * Builds a function using a custom numeric field and |
10 | * parameters attached to a profile. |
11 | * Uses the function field_value_factor |
12 | */ |
13 | class CustomFieldFunctionScoreBuilder extends FunctionScoreBuilder { |
14 | /** |
15 | * @var array the field_value_factor profile |
16 | */ |
17 | private $profile; |
18 | |
19 | /** |
20 | * @param SearchConfig $config |
21 | * @param float $weight |
22 | * @param array $profile |
23 | */ |
24 | public function __construct( SearchConfig $config, $weight, $profile ) { |
25 | parent::__construct( $config, $weight ); |
26 | if ( isset( $profile['factor'] ) ) { |
27 | $profile['factor'] = $this->getOverriddenFactor( $profile['factor'] ); |
28 | } |
29 | $this->profile = $profile; |
30 | } |
31 | |
32 | public function append( FunctionScore $functionScore ) { |
33 | if ( isset( $this->profile['factor'] ) && $this->profile['factor'] === 0.0 ) { |
34 | // If factor is 0 this function score will have no impact. |
35 | return; |
36 | } |
37 | $functionScore->addFunction( 'field_value_factor', $this->profile, null, $this->weight ); |
38 | } |
39 | } |