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 | */ |
15 | class GeoRadiusFunctionScoreBuilder extends FunctionScoreBuilder { |
16 | /** |
17 | * Default feature weight |
18 | */ |
19 | private const DEFAULT_WEIGHT = 2; |
20 | private Coord $coord; |
21 | /** |
22 | * @var int |
23 | */ |
24 | private $radius; |
25 | |
26 | /** |
27 | * @param SearchConfig $config |
28 | * @param float $weight Used to amend profile weight, e.g. negative boosting |
29 | * @param Coord $coord Center coordinate |
30 | * @param int $radius |
31 | */ |
32 | public function __construct( SearchConfig $config, $weight, Coord $coord, $radius ) { |
33 | $weightProfile = $config->get( 'GeoDataRadiusScoreOverrides' ); |
34 | $weightProfile['value'] = self::DEFAULT_WEIGHT; |
35 | // Overrides will be applied to weight in parent ctor |
36 | parent::__construct( $config, $weightProfile ); |
37 | $this->weight *= $weight; |
38 | $this->coord = $coord; |
39 | $this->radius = $radius; |
40 | } |
41 | |
42 | public function append( FunctionScore $functionScore ) { |
43 | $functionScore->addWeightFunction( $this->weight, |
44 | CirrusNearTitleFilterFeature::createQuery( $this->coord, $this->radius ) ); |
45 | } |
46 | } |