Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 15 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| CoordinatesIndexField | |
0.00% |
0 / 15 |
|
0.00% |
0 / 2 |
12 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| build | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace GeoData\Search; |
| 4 | |
| 5 | use CirrusSearch\Search\NestedIndexField; |
| 6 | use CirrusSearch\SearchConfig; |
| 7 | use SearchEngine; |
| 8 | use SearchIndexField; |
| 9 | |
| 10 | /** |
| 11 | * Nested type for CirrusSearch mapping |
| 12 | */ |
| 13 | class CoordinatesIndexField extends NestedIndexField { |
| 14 | /** |
| 15 | * @param string $name name of the field |
| 16 | * @param SearchConfig $config CirrusSearch config |
| 17 | */ |
| 18 | public function __construct( $name, SearchConfig $config ) { |
| 19 | parent::__construct( $name, $this->typeName, $config ); |
| 20 | } |
| 21 | |
| 22 | /** |
| 23 | * Builds a new CoordinatesIndexField nested field |
| 24 | * @param string $name field name |
| 25 | * @param SearchConfig $config |
| 26 | * @param SearchEngine $engine |
| 27 | * @return self |
| 28 | */ |
| 29 | public static function build( $name, SearchConfig $config, SearchEngine $engine ): self { |
| 30 | $nested = new self( $name, $config ); |
| 31 | $nested->addSubfield( 'coord', new GeoPointIndexField( 'coord', $config ) ); |
| 32 | // Setting analyzer to keyword is similar to index => not_analyzed |
| 33 | $keywords = [ 'globe', 'type', 'country', 'region' ]; |
| 34 | foreach ( $keywords as $keyword ) { |
| 35 | $nested->addSubfield( $keyword, $engine->makeSearchFieldMapping( $keyword, |
| 36 | SearchIndexField::INDEX_TYPE_KEYWORD ) ); |
| 37 | } |
| 38 | $nested->addSubfield( 'primary', $engine->makeSearchFieldMapping( 'primary', |
| 39 | SearchIndexField::INDEX_TYPE_BOOL ) ); |
| 40 | $nested->addSubfield( 'dim', $engine->makeSearchFieldMapping( 'dim', |
| 41 | SearchIndexField::INDEX_TYPE_NUMBER ) ); |
| 42 | $name = $engine->makeSearchFieldMapping( 'name', SearchIndexField::INDEX_TYPE_TEXT ); |
| 43 | $name->setFlag( SearchIndexField::FLAG_NO_INDEX ); |
| 44 | $nested->addSubfield( 'name', $name ); |
| 45 | return $nested; |
| 46 | } |
| 47 | } |