Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
15.38% |
2 / 13 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
LemmaField | |
15.38% |
2 / 13 |
|
0.00% |
0 / 3 |
20.15 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getMapping | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
6 | |||
getFieldData | |
66.67% |
2 / 3 |
|
0.00% |
0 / 1 |
2.15 |
1 | <?php |
2 | namespace Wikibase\Lexeme\Search\Elastic; |
3 | |
4 | use CirrusSearch\CirrusSearch; |
5 | use SearchEngine; |
6 | use Wikibase\DataModel\Entity\EntityDocument; |
7 | use Wikibase\Lexeme\Domain\Model\Lexeme; |
8 | use Wikibase\Search\Elastic\Fields\TermIndexField; |
9 | |
10 | /** |
11 | * Field implementing Lexeme's lemma |
12 | */ |
13 | class LemmaField extends TermIndexField { |
14 | |
15 | public const NAME = 'lemma'; |
16 | |
17 | public function __construct() { |
18 | parent::__construct( static::NAME, \SearchIndexField::INDEX_TYPE_TEXT ); |
19 | } |
20 | |
21 | /** |
22 | * @param SearchEngine $engine |
23 | * |
24 | * @return array |
25 | */ |
26 | public function getMapping( SearchEngine $engine ) { |
27 | // Since we need a specially tuned field, we can not use |
28 | // standard search engine types. |
29 | if ( !( $engine instanceof CirrusSearch ) ) { |
30 | // For now only Cirrus/Elastic is supported |
31 | return []; |
32 | } |
33 | |
34 | $config = $this->getUnindexedField(); |
35 | $config['fields']['prefix'] = |
36 | $this->getSubfield( 'prefix_asciifolding', 'near_match_asciifolding' ); |
37 | $config['fields']['near_match'] = $this->getSubfield( 'near_match' ); |
38 | $config['fields']['near_match_folded'] = $this->getSubfield( 'near_match_asciifolding' ); |
39 | // TODO: we don't seem to be using this, check if we need it? |
40 | $config['copy_to'] = 'labels_all'; |
41 | |
42 | return $config; |
43 | } |
44 | |
45 | /** |
46 | * @param EntityDocument $entity |
47 | * |
48 | * @return mixed Get the value of the field to be indexed when a page/document |
49 | * is indexed. This might be an array with nested data, if the field |
50 | * is defined with nested type or an int or string for simple field types. |
51 | */ |
52 | public function getFieldData( EntityDocument $entity ) { |
53 | if ( !( $entity instanceof Lexeme ) ) { |
54 | return []; |
55 | } |
56 | /** |
57 | * @var Lexeme $entity |
58 | */ |
59 | return array_values( $entity->getLemmas()->toTextArray() ); |
60 | } |
61 | |
62 | } |