Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
AllLabelsField
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
3 / 3
4
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getMapping
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
2
 getFieldData
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2namespace Wikibase\Search\Elastic\Fields;
3
4use CirrusSearch\CirrusSearch;
5use SearchEngine;
6use Wikibase\DataModel\Entity\EntityDocument;
7
8/**
9 * Field which contains combination of all labels.
10 *
11 * @license GPL-2.0-or-later
12 * @author Stas Malyshev
13 */
14class AllLabelsField extends TermIndexField {
15
16    /**
17     * Field name
18     */
19    public const NAME = 'labels_all';
20
21    public function __construct() {
22        parent::__construct( static::NAME, \SearchIndexField::INDEX_TYPE_TEXT );
23    }
24
25    /**
26     * @param SearchEngine $engine
27     * @return array
28     */
29    public function getMapping( SearchEngine $engine ) {
30        // Since we need a specially tuned field, we can not use
31        // standard search engine types.
32        if ( !( $engine instanceof CirrusSearch ) ) {
33            // For now only Cirrus/Elastic is supported
34            return [];
35        }
36
37        $config = $this->getUnindexedField();
38        $config['fields']['prefix'] =
39            $this->getSubfield( 'prefix_asciifolding', 'near_match_asciifolding' );
40        $config['fields']['near_match_folded'] = $this->getSubfield( 'near_match_asciifolding' );
41        $config['fields']['plain'] = $this->getTokenizedSubfield( $engine->getConfig(),
42            'plain', 'plain_search' );
43
44        return $config;
45    }
46
47    /**
48     * @param EntityDocument $entity
49     *
50     * @return null Always returns null since this field is filled in by copy from other fields.
51     */
52    public function getFieldData( EntityDocument $entity ) {
53        // All-labels has no data, it is assembled from individual fields by Elastic via copy_to.
54        return null;
55    }
56
57}