Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
88.89% |
8 / 9 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
ByKeywordTemplateBoostFunction | |
88.89% |
8 / 9 |
|
50.00% |
1 / 2 |
3.01 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
2 | |||
append | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace CirrusSearch\Search\Rescore; |
4 | |
5 | class ByKeywordTemplateBoostFunction implements BoostFunctionBuilder { |
6 | |
7 | /** |
8 | * @var \CirrusSearch\Search\Rescore\BoostedQueriesFunction |
9 | */ |
10 | private $queries; |
11 | |
12 | /** |
13 | * @param array $boostTemplates |
14 | */ |
15 | public function __construct( array $boostTemplates ) { |
16 | $queries = []; |
17 | $weights = []; |
18 | foreach ( $boostTemplates as $name => $weight ) { |
19 | $match = new \Elastica\Query\MatchQuery(); |
20 | $match->setFieldQuery( 'template', $name ); |
21 | $weights[] = $weight; |
22 | $queries[] = $match; |
23 | } |
24 | |
25 | $this->queries = new BoostedQueriesFunction( $queries, $weights ); |
26 | } |
27 | |
28 | /** |
29 | * Append functions to the function score $container |
30 | * |
31 | * @param \Elastica\Query\FunctionScore $container |
32 | */ |
33 | public function append( \Elastica\Query\FunctionScore $container ) { |
34 | $this->queries->append( $container ); |
35 | } |
36 | } |