I’m try to create autocomplete with substring highlighting feature for example if I type sam it should return samsung but it return full word with highlighting like samsung. Please suggest what should I do. Here’s is my model code:
public function attributes()
{
return['id', 'name', 'email'];
}
public static function mapping()
{
return [
static::type() => [
'properties' => [
'id' => ['type' => 'integer'],
'name' => [
'type' => 'string',
"analyzer" => "autocomplete",
"search_analyzer" => "standard",
],
'email' => ['type' => 'string'],
]
],
];
}
/**
* Create this model's index
*/
public static function createIndex()
{
$db = static::getDb();
$command = $db->createCommand();
$command->createIndex(static::index(), [
'settings' => [
'number_of_shards' => 1,
'analysis' => [
'analyzer' => [
"autocomplete" => [
"type" => "custom",
"tokenizer" => "standard",
"filter" => ["lowercase", "autocomplete_filter"],
],
],
'filter' => [
"autocomplete_filter" => [
"type" => "edge_ngram",
"min_gram" => 2,
"max_gram" => 15,
],
],
],
],
'mappings' => static::mapping(),
//'warmers' => [ /* ... */ ],
//'aliases' => [ /* ... */ ],
//'creation_date' => '...'
]);
}