-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make some necessary changes to meet the requirements of elasticsearch…
…_connector 8.x
- Loading branch information
1 parent
7bdd2d0
commit 3ba0896
Showing
5 changed files
with
167 additions
and
0 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
modules/tide_search/config/optional/search_api.server.elasticsearch_bay.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
uuid: ff7ac093-067c-4a15-98f4-2ab4dfda7b9c | ||
langcode: en | ||
status: true | ||
dependencies: | ||
module: | ||
- elasticsearch_connector | ||
_core: | ||
default_config_hash: 4ulEtCC_6q-TNQFpsg_DJsn4keGx1hpp6ZlcMtKggzo | ||
id: elasticsearch_bay | ||
name: 'Elasticsearch on Bay' | ||
description: '' | ||
backend: elasticsearch | ||
backend_config: | ||
connector: standard | ||
connector_config: | ||
url: 'http://elasticsearch:9200' | ||
enable_debug_logging: true | ||
advanced: | ||
fuzziness: auto | ||
prefix: elasticsearch_index_drupal_ | ||
suffix: '' | ||
synonyms: | ||
- '' |
99 changes: 99 additions & 0 deletions
99
modules/tide_search/src/EventSubscriber/ElasticSearchEventSubscribers.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
<?php | ||
|
||
namespace Drupal\tide_search\EventSubscriber; | ||
|
||
use Drupal\elasticsearch_connector\Event\AlterSettingsEvent; | ||
use Drupal\elasticsearch_connector\Event\FieldMappingEvent; | ||
use Drupal\elasticsearch_connector\Event\SupportsDataTypeEvent; | ||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
|
||
/** | ||
* ElasticSearch test event subscribers. | ||
*/ | ||
class ElasticSearchEventSubscribers implements EventSubscriberInterface { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function getSubscribedEvents(): array { | ||
return [ | ||
AlterSettingsEvent::class => 'onAlterSettingsEvent', | ||
FieldMappingEvent::class => 'onFieldMappingEvent', | ||
SupportsDataTypeEvent::class => 'onSupportsDataTypeEvent', | ||
]; | ||
} | ||
|
||
/** | ||
* Event handler for SupportsDataTypeEvent. | ||
*/ | ||
public function onSupportsDataTypeEvent(SupportsDataTypeEvent $event): void { | ||
if ($event->getType() === 'tide_search_text_field_with_keyword_and_prefix') { | ||
$event->setIsSupported(TRUE); | ||
} | ||
} | ||
|
||
/** | ||
* Event handler for FieldMappingEvent. | ||
*/ | ||
public function onFieldMappingEvent(FieldMappingEvent $event): void { | ||
$param = $event->getParam(); | ||
$field = $event->getField(); | ||
$type = $field->getType(); | ||
$param = match ($type) { | ||
'tide_search_text_field_with_keyword_and_prefix' => [ | ||
"type" => "text", | ||
"fields" => [ | ||
"keyword" => [ | ||
"type" => "keyword", | ||
"ignore_above" => 256, | ||
], | ||
"prefix" => [ | ||
"type" => "text", | ||
"index_options" => "docs", | ||
"analyzer" => "i_prefix", | ||
"search_analyzer" => "q_prefix", | ||
], | ||
], | ||
], | ||
default => [], | ||
}; | ||
$event->setParam($param); | ||
} | ||
|
||
/** | ||
* Event handler for AlterSettingsEvent. | ||
*/ | ||
public function onAlterSettingsEvent(AlterSettingsEvent $event): void { | ||
$settings = $event->getSettings(); | ||
$settings['analysis'] = [ | ||
"filter" => [ | ||
"front_ngram" => [ | ||
"type" => "edge_ngram", | ||
"min_gram" => "1", | ||
"max_gram" => "12", | ||
], | ||
], | ||
"analyzer" => [ | ||
"i_prefix" => [ | ||
"filter" => [ | ||
"cjk_width", | ||
"lowercase", | ||
"asciifolding", | ||
"front_ngram", | ||
], | ||
"tokenizer" => "standard", | ||
], | ||
"q_prefix" => [ | ||
"filter" => [ | ||
"cjk_width", | ||
"lowercase", | ||
"asciifolding", | ||
], | ||
"tokenizer" => "standard", | ||
], | ||
], | ||
]; | ||
$event->setSettings($settings); | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
modules/tide_search/src/Plugin/search_api/data_type/TextFieldWithKeywordAndPrefix.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Drupal\tide_search\Plugin\search_api\data_type; | ||
|
||
use Drupal\search_api\Plugin\search_api\data_type\TextDataType; | ||
|
||
/** | ||
* Defines a class for a Text Field with Keyword and Prefix Subfields data type. | ||
* | ||
* @SearchApiDataType( | ||
* id = "tide_search_text_field_with_keyword_and_prefix", | ||
* label = @Translation("Text Field with Keyword and Prefix Subfields"), | ||
* description = @Translation("Text Field with Keyword and Prefix Subfields"), | ||
* fallback_type = "text", | ||
* ) | ||
*/ | ||
final class TextFieldWithKeywordAndPrefix extends TextDataType { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
services: | ||
tide_search.event_subscriber: | ||
class: Drupal\tide_search\EventSubscriber\ElasticSearchEventSubscribers | ||
tags: | ||
- { name: event_subscriber } |