Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 12 |
KeywordIndexField | |
0.00% |
0 / 1 |
|
0.00% |
0 / 2 |
30 | |
0.00% |
0 / 12 |
__construct | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 5 |
|||
getMapping | |
0.00% |
0 / 1 |
12 | |
0.00% |
0 / 7 |
<?php | |
namespace CirrusSearch\Search; | |
use CirrusSearch\SearchConfig; | |
use SearchIndexField; | |
/** | |
* Index field representing keyword. | |
* Keywords use special analyzer. | |
* @package CirrusSearch | |
*/ | |
class KeywordIndexField extends CirrusIndexField { | |
/** | |
* Using text type here since it's better for our purposes than native | |
* keyword type. | |
* @var string | |
*/ | |
protected $typeName = 'text'; | |
/** | |
* @var bool | |
*/ | |
private $caseSensitiveSubfield; | |
public function __construct( $name, $type, SearchConfig $config, bool $caseSensitiveSubfield = false ) { | |
parent::__construct( $name, $type, $config ); | |
if ( $caseSensitiveSubfield ) { | |
$this->setFlag( SearchIndexField::FLAG_CASEFOLD ); | |
} | |
$this->caseSensitiveSubfield = $caseSensitiveSubfield; | |
} | |
/** | |
* Maximum number of characters allowed in keyword terms. | |
*/ | |
private const KEYWORD_IGNORE_ABOVE = 5000; | |
public function getMapping( \SearchEngine $engine ) { | |
$config = parent::getMapping( $engine ); | |
$config['analyzer'] = | |
$this->checkFlag( self::FLAG_CASEFOLD ) ? 'lowercase_keyword' : 'keyword'; | |
$config += [ | |
'norms' => false, | |
// Omit the length norm because there is only even one token | |
'index_options' => 'docs', | |
]; | |
if ( $this->caseSensitiveSubfield ) { | |
$config['fields']['keyword'] = [ | |
'type' => 'text', | |
'analyzer' => 'keyword', | |
'index_options' => 'docs', | |
'norms' => false, | |
]; | |
} | |
return $config; | |
} | |
} |