You are here

public function DefaultSubscriber::elasticsearchConnectorPrepareIndex in Elasticsearch Connector Autocomplete 8

Called on elasticsearch_connector.prepare_index event.

Parameters

\Symfony\Component\EventDispatcher\Event $event: The event.

File

src/EventSubscriber/DefaultSubscriber.php, line 90

Class

DefaultSubscriber
Class DefaultSubscriber.

Namespace

Drupal\elasticsearch_connector_autocomp\EventSubscriber

Code

public function elasticsearchConnectorPrepareIndex(Event $event) {
  $index = $this
    ->loadIndexFromIndexName($event
    ->getIndexName());
  $settings = $index
    ->getThirdPartySettings('elasticsearch_connector');
  $indexConfig = $event
    ->getIndexConfig();
  if (!empty($settings['ngram_filter_enabled'])) {
    $body = <<<EOF
{
\t"settings": {
\t\t"analysis": {
\t\t\t"filter": {
\t\t\t\t"ngram_filter": {
\t\t\t\t\t"type": "{<span class="php-variable">$settings</span>[<span class="php-string">'ngram_config'</span>][<span class="php-string">'ngram_type'</span>]}",
\t\t\t\t\t"min_gram": {<span class="php-variable">$settings</span>[<span class="php-string">'ngram_config'</span>][<span class="php-string">'min_gram'</span>]},
\t\t\t\t\t"max_gram": {<span class="php-variable">$settings</span>[<span class="php-string">'ngram_config'</span>][<span class="php-string">'max_gram'</span>]}
\t\t\t\t}
\t\t\t},
\t\t\t"analyzer": {
\t\t\t\t"ngram_analyzer": {
\t\t\t\t\t"type": "custom",
\t\t\t\t\t"tokenizer": "standard",
\t\t\t\t\t"filter": [
\t\t\t\t\t\t"lowercase",
\t\t\t\t\t\t"ngram_filter"
\t\t\t\t\t]
\t\t\t\t}
\t\t\t}
\t\t}
\t}
}
EOF;
    $body = json_decode($body, TRUE);
    $indexConfig['body'] = array_merge($indexConfig['body'], $body);
  }
  $event
    ->setIndexConfig($indexConfig);
}