Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
50.00% covered (danger)
50.00%
1 / 2
CRAP
81.82% covered (warning)
81.82%
9 / 11
ByKeywordTemplateBoostFunction
0.00% covered (danger)
0.00%
0 / 1
50.00% covered (danger)
50.00%
1 / 2
3.05
81.82% covered (warning)
81.82%
9 / 11
 __construct
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
9 / 9
 append
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
<?php
namespace CirrusSearch\Search\Rescore;
class ByKeywordTemplateBoostFunction implements BoostFunctionBuilder {
    /**
     * @var \CirrusSearch\Search\Rescore\BoostedQueriesFunction
     */
    private $queries;
    /**
     * @param array $boostTemplates
     */
    public function __construct( array $boostTemplates ) {
        $queries = [];
        $weights = [];
        foreach ( $boostTemplates as $name => $weight ) {
            $match = new \Elastica\Query\MatchQuery();
            $match->setFieldQuery( 'template', $name );
            $weights[] = $weight;
            $queries[] = $match;
        }
        $this->queries = new BoostedQueriesFunction( $queries, $weights );
    }
    /**
     * Append functions to the function score $container
     *
     * @param \Elastica\Query\FunctionScore $container
     */
    public function append( \Elastica\Query\FunctionScore $container ) {
        $this->queries->append( $container );
    }
}