Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 8 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
GeoRadiusFunctionScoreBuilder | |
0.00% |
0 / 8 |
|
0.00% |
0 / 2 |
6 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
append | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace GeoData\Search; |
4 | |
5 | use CirrusSearch\Search\Rescore\FunctionScoreBuilder; |
6 | use CirrusSearch\SearchConfig; |
7 | use Elastica\Query\FunctionScore; |
8 | use GeoData\Coord; |
9 | |
10 | /** |
11 | * Builds a boost for documents based on geocoordinates. |
12 | * Initialized by special syntax in user query. |
13 | * @see CirrusGeoFeature |
14 | * @package GeoData |
15 | */ |
16 | class GeoRadiusFunctionScoreBuilder extends FunctionScoreBuilder { |
17 | /** |
18 | * Default feature weight |
19 | */ |
20 | private const DEFAULT_WEIGHT = 2; |
21 | /** |
22 | * @var Coord |
23 | */ |
24 | private $coord; |
25 | /** |
26 | * @var int |
27 | */ |
28 | private $radius; |
29 | |
30 | /** |
31 | * @param SearchConfig $config |
32 | * @param float $weight Used to amend profile weight, e.g. negative boosting |
33 | * @param Coord $coord Center coordinate |
34 | * @param int $radius |
35 | */ |
36 | public function __construct( SearchConfig $config, $weight, Coord $coord, $radius ) { |
37 | $weightProfile = $config->get( 'GeoDataRadiusScoreOverrides' ); |
38 | $weightProfile['value'] = self::DEFAULT_WEIGHT; |
39 | // Overrides will be applied to weight in parent ctor |
40 | parent::__construct( $config, $weightProfile ); |
41 | $this->weight *= $weight; |
42 | $this->coord = $coord; |
43 | $this->radius = $radius; |
44 | } |
45 | |
46 | /** |
47 | * @param FunctionScore $functionScore |
48 | */ |
49 | public function append( FunctionScore $functionScore ) { |
50 | $functionScore->addWeightFunction( $this->weight, |
51 | CirrusNearTitleFilterFeature::createQuery( $this->coord, $this->radius ) ); |
52 | } |
53 | } |