Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 10
LexemeKeywordField
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 3
30
0.00% covered (danger)
0.00%
0 / 10
 __construct
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 getMapping
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 5
 getMappingField
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 3
<?php
namespace Wikibase\Lexeme\Search\Elastic;
use CirrusSearch\CirrusSearch;
use CirrusSearch\Search\KeywordIndexField;
use SearchEngine;
use SearchIndexField;
use SearchIndexFieldDefinition;
use Wikibase\Repo\Search\Fields\WikibaseIndexField;
/**
 * Keyword field for lexeme implementation
 */
abstract class LexemeKeywordField extends SearchIndexFieldDefinition implements WikibaseIndexField {
    public const NAME = "unknown_field";
    public function __construct() {
        parent::__construct( static::NAME, \SearchIndexField::INDEX_TYPE_KEYWORD );
    }
    /**
     * @param SearchEngine $engine
     *
     * @return array
     */
    public function getMapping( SearchEngine $engine ) {
        // Since we need a specially tuned field, we can not use
        // standard search engine types.
        if ( !( $engine instanceof CirrusSearch ) ) {
            // For now only Cirrus/Elastic is supported
            return [];
        }
        $keyword = new KeywordIndexField( $this->getName(), $this->getIndexType(), $engine->getConfig() );
        $keyword->setFlag( self::FLAG_CASEFOLD );
        return $keyword->getMapping( $engine );
    }
    /**
     * Produce specific field mapping
     *
     * @param SearchEngine $engine
     * @param string $name
     *
     * @return SearchIndexField|null
     */
    public function getMappingField( SearchEngine $engine, $name ) {
        if ( !( $engine instanceof CirrusSearch ) ) {
            // For now only Cirrus/Elastic is supported
            return null;
        }
        return $this;
    }
}