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