Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
LexemeKeywordField
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 3
30
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getMapping
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
6
 getMappingField
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2namespace Wikibase\Lexeme\Search\Elastic;
3
4use CirrusSearch\CirrusSearch;
5use CirrusSearch\Search\KeywordIndexField;
6use SearchEngine;
7use SearchIndexField;
8use SearchIndexFieldDefinition;
9use Wikibase\Repo\Search\Fields\WikibaseIndexField;
10
11/**
12 * Keyword field for lexeme implementation
13 */
14abstract class LexemeKeywordField extends SearchIndexFieldDefinition implements WikibaseIndexField {
15
16    public const NAME = "unknown_field";
17
18    public function __construct() {
19        parent::__construct( static::NAME, \SearchIndexField::INDEX_TYPE_KEYWORD );
20    }
21
22    /**
23     * @param SearchEngine $engine
24     *
25     * @return array
26     */
27    public function getMapping( SearchEngine $engine ) {
28        // Since we need a specially tuned field, we can not use
29        // standard search engine types.
30        if ( !( $engine instanceof CirrusSearch ) ) {
31            // For now only Cirrus/Elastic is supported
32            return [];
33        }
34
35        $keyword = new KeywordIndexField( $this->getName(), $this->getIndexType(), $engine->getConfig() );
36        $keyword->setFlag( self::FLAG_CASEFOLD );
37        return $keyword->getMapping( $engine );
38    }
39
40    /**
41     * Produce specific field mapping
42     *
43     * @param SearchEngine $engine
44     * @param string $name
45     *
46     * @return SearchIndexField|null
47     */
48    public function getMappingField( SearchEngine $engine, $name ) {
49        if ( !( $engine instanceof CirrusSearch ) ) {
50            // For now only Cirrus/Elastic is supported
51            return null;
52        }
53        return $this;
54    }
55
56}