diff --git a/config/schema/search_api.index.schema.yml b/config/schema/search_api.index.schema.yml index 732d9b8..6f7eb60 100644 --- a/config/schema/search_api.index.schema.yml +++ b/config/schema/search_api.index.schema.yml @@ -17,6 +17,24 @@ search_api.index.*: read_only: type: boolean label: 'Read-only' + processors: + type: sequence + label: 'Processor settings' + sequence: + type: mapping + label: 'A processor' + mapping: + processor_id: + type: string + label: 'The plugin ID of the processor' + weights: + type: sequence + label: 'The processor''s weights for the different processing stages' + sequence: + type: integer + label: 'The processor''s weight for this stage' + settings: + type: plugin.plugin_configuration.search_api_processor.[%parent.processor_id] options: type: mapping label: 'Options' @@ -46,24 +64,6 @@ search_api.index.*: index_directly: type: boolean label: 'Index items immediately' - processors: - type: sequence - label: 'Processor settings' - sequence: - type: mapping - label: 'A processor' - mapping: - processor_id: - type: string - label: 'The plugin ID of the processor' - weights: - type: sequence - label: 'The processor''s weights for the different processing stages' - sequence: - type: integer - label: 'The processor''s weight for this stage' - settings: - type: plugin.plugin_configuration.search_api_processor.[%parent.processor_id] datasources: type: sequence label: 'Datasource plugin IDs' diff --git a/search_api_db/search_api_db_defaults/config/optional/search_api.index.default_index.yml b/search_api_db/search_api_db_defaults/config/optional/search_api.index.default_index.yml index 57f0ee8..691992a 100644 --- a/search_api_db/search_api_db_defaults/config/optional/search_api.index.default_index.yml +++ b/search_api_db/search_api_db_defaults/config/optional/search_api.index.default_index.yml @@ -2,138 +2,138 @@ id: default_index name: 'Default content index' description: 'Default content index created by the Database Search Defaults module' read_only: false +processors: + content_access: + processor_id: content_access + weights: + preprocess_index: -6 + preprocess_query: -4 + settings: { } + highlight: + processor_id: highlight + weights: + postprocess_query: -9 + settings: + highlight: always + excerpt: true + excerpt_length: 256 + prefix: '' + suffix: '' + html_filter: + processor_id: html_filter + weights: + preprocess_index: -3 + preprocess_query: -6 + settings: + fields: + - rendered_item + title: true + alt: true + tags: + h1: 5 + h2: 3 + h3: 2 + string: 2 + b: 2 + ignorecase: + processor_id: ignorecase + weights: + preprocess_index: -5 + preprocess_query: -8 + settings: + fields: + - rendered_item + - 'entity:node/title' + language: + processor_id: language + weights: + preprocess_index: -50 + settings: { } + node_status: + processor_id: node_status + weights: + preprocess_index: -10 + settings: { } + rendered_item: + processor_id: rendered_item + weights: + preprocess_index: -8 + settings: + roles: + anonymous: anonymous + view_mode: + 'entity:node': + article: search_index + page: search_index + stopwords: + processor_id: stopwords + weights: + preprocess_query: -10 + postprocess_query: -10 + settings: + fields: + - rendered_item + - 'entity:node/title' + stopwords: + - a + - an + - and + - are + - as + - at + - be + - but + - by + - for + - if + - in + - into + - is + - it + - 'no' + - not + - of + - 'on' + - or + - s + - such + - t + - that + - the + - their + - then + - there + - these + - they + - this + - to + - was + - will + - with + tokenizer: + processor_id: tokenizer + weights: + preprocess_index: -2 + preprocess_query: -5 + settings: + fields: + - rendered_item + - 'entity:node/title' + spaces: '' + overlap_cjk: 1 + minimum_word_size: '3' + transliteration: + processor_id: transliteration + weights: + preprocess_index: -4 + preprocess_query: -7 + settings: + fields: + - rendered_item + - 'entity:node/title' options: index_directly: true cron_limit: 50 - processors: - content_access: - processor_id: content_access - weights: - preprocess_index: -6 - preprocess_query: -4 - settings: { } - highlight: - processor_id: highlight - weights: - postprocess_query: -9 - settings: - highlight: always - excerpt: true - excerpt_length: 256 - prefix: '' - suffix: '' - html_filter: - processor_id: html_filter - weights: - preprocess_index: -3 - preprocess_query: -6 - settings: - fields: - - rendered_item - title: true - alt: true - tags: - h1: 5 - h2: 3 - h3: 2 - string: 2 - b: 2 - ignorecase: - processor_id: ignorecase - weights: - preprocess_index: -5 - preprocess_query: -8 - settings: - fields: - - rendered_item - - 'entity:node/title' - language: - processor_id: language - weights: - preprocess_index: -50 - settings: { } - node_status: - processor_id: node_status - weights: - preprocess_index: -10 - settings: { } - rendered_item: - processor_id: rendered_item - weights: - preprocess_index: -8 - settings: - roles: - anonymous: anonymous - view_mode: - 'entity:node': - article: search_index - page: search_index - stopwords: - processor_id: stopwords - weights: - preprocess_query: -10 - postprocess_query: -10 - settings: - fields: - - rendered_item - - 'entity:node/title' - stopwords: - - a - - an - - and - - are - - as - - at - - be - - but - - by - - for - - if - - in - - into - - is - - it - - 'no' - - not - - of - - 'on' - - or - - s - - such - - t - - that - - the - - their - - then - - there - - these - - they - - this - - to - - was - - will - - with - tokenizer: - processor_id: tokenizer - weights: - preprocess_index: -2 - preprocess_query: -5 - settings: - fields: - - rendered_item - - 'entity:node/title' - spaces: '' - overlap_cjk: 1 - minimum_word_size: '3' - transliteration: - processor_id: transliteration - weights: - preprocess_index: -4 - preprocess_query: -7 - settings: - fields: - - rendered_item - - 'entity:node/title' fields: search_api_language: type: string diff --git a/search_api_db/src/Plugin/search_api/backend/Database.php b/search_api_db/src/Plugin/search_api/backend/Database.php index b1d9fc4..2336a9e 100644 --- a/search_api_db/src/Plugin/search_api/backend/Database.php +++ b/search_api_db/src/Plugin/search_api/backend/Database.php @@ -1283,7 +1283,7 @@ class Database extends BackendPluginBase { if (count($words) > 1 && max(array_map('strlen', $words)) <= 50) { // Overlong token is due to bad tokenizing. // Check for "Tokenizer" preprocessor on index. - if (empty($index->getOption('processors')['search_api_tokenizer']['status'])) { + if (empty($index->getProcessorSettings()['search_api_tokenizer']['status'])) { $this->getLogger()->warning('An overlong word (more than 50 characters) was encountered while indexing, due to bad tokenizing. It is recommended to enable the "Tokenizer" preprocessor for indexes using database servers. Otherwise, the backend class has to use its own, fixed tokenizing.'); } else { diff --git a/search_api_db/src/Tests/BackendTest.php b/search_api_db/src/Tests/BackendTest.php index ea48701..725315a 100644 --- a/search_api_db/src/Tests/BackendTest.php +++ b/search_api_db/src/Tests/BackendTest.php @@ -188,13 +188,13 @@ class BackendTest extends EntityUnitTestBase { $index->getFields(FALSE)[$this->getFieldId('body')]->setIndexed(TRUE, TRUE); - $processors = $index->getOption('processors', array()); + $processors = $index->getProcessorSettings(); $processors['html_filter'] = array( 'processor_id' => 'html_filter', 'weights' => array(), 'settings' => array(), ); - $index->setOption('processors', $processors); + $index->setProcessorSettings($processors); $index->save(); } @@ -204,9 +204,9 @@ class BackendTest extends EntityUnitTestBase { protected function disableHtmlFilter() { /** @var \Drupal\search_api\IndexInterface $index */ $index = $this->getIndex(); - $processors = $index->getOption('processors'); + $processors = $index->getProcessorSettings(); unset($processors['html_filter']); - $index->setOption('processors', $processors); + $index->setProcessorSettings($processors); $index->getFields()[$this->getFieldId('body')]->setIndexed(FALSE, TRUE); $index->save(); } diff --git a/src/Entity/Index.php b/src/Entity/Index.php index 8a07deb..d814c8d 100644 --- a/src/Entity/Index.php +++ b/src/Entity/Index.php @@ -61,6 +61,7 @@ use Drupal\views\Views; * "description", * "read_only", * "options", + * "processors", * "datasources", * "datasource_configs", * "tracker", @@ -248,7 +249,9 @@ class Index extends ConfigEntityBase implements IndexInterface { * * @see loadProcessors() */ - protected $processors; + protected $processorInstances; + + protected $processors = array(); /** * List of types that failed to map to a Search API type. @@ -485,7 +488,7 @@ class Index extends ConfigEntityBase implements IndexInterface { // Filter processors by status if required. Enabled processors are those // which have settings in the "processors" option. if ($only_enabled) { - $processors_settings = $this->getOption('processors', array()); + $processors_settings = $this->getProcessorSettings(); $processors = array_intersect_key($processors, $processors_settings); } @@ -497,7 +500,7 @@ class Index extends ConfigEntityBase implements IndexInterface { */ public function getProcessorsByStage($stage, $only_enabled = TRUE) { $processors = $this->loadProcessors(); - $processor_settings = $this->getOption('processors', array()); + $processor_settings = $this->getProcessorSettings(); $processor_weights = array(); // Get a list of all processors meeting the criteria (stage and, optionally, @@ -530,13 +533,13 @@ class Index extends ConfigEntityBase implements IndexInterface { * The loaded processors, keyed by processor ID. */ protected function loadProcessors() { - if (!isset($this->processors)) { + if (!isset($this->processorInstances)) { /** @var $processor_plugin_manager \Drupal\search_api\Processor\ProcessorPluginManager */ $processor_plugin_manager = \Drupal::service('plugin.manager.search_api.processor'); - $processor_settings = $this->getOption('processors', array()); + $processor_settings = $this->getProcessorSettings(); foreach ($processor_plugin_manager->getDefinitions() as $name => $processor_definition) { - if (class_exists($processor_definition['class']) && empty($this->processors[$name])) { + if (class_exists($processor_definition['class']) && empty($this->processorInstances[$name])) { // Create our settings for this processor. $settings = empty($processor_settings[$name]['settings']) ? array() : $processor_settings[$name]['settings']; $settings['index'] = $this; @@ -544,7 +547,7 @@ class Index extends ConfigEntityBase implements IndexInterface { /** @var $processor \Drupal\search_api\Processor\ProcessorInterface */ $processor = $processor_plugin_manager->createInstance($name, $settings); if ($processor->supportsIndex($this)) { - $this->processors[$name] = $processor; + $this->processorInstances[$name] = $processor; } } elseif (!class_exists($processor_definition['class'])) { @@ -553,6 +556,21 @@ class Index extends ConfigEntityBase implements IndexInterface { } } + return $this->processorInstances; + } + + /** + * {@inheritdoc} + */ + public function setProcessorSettings(array $processors) { + $this->processors = $processors; + return $this; + } + + /** + * {@inheritdoc} + */ + public function getProcessorSettings() { return $this->processors; } @@ -1177,7 +1195,7 @@ class Index extends ConfigEntityBase implements IndexInterface { $this->fields = NULL; $this->datasourceFields = NULL; $this->fulltextFields = NULL; - $this->processors = NULL; + $this->processorInstances = NULL; $this->properties = NULL; $this->datasourceAdditionalFields = NULL; if ($include_stored) { @@ -1221,8 +1239,8 @@ class Index extends ConfigEntityBase implements IndexInterface { // Obviously, we should first check for locked processors, because they // might add new locked properties. foreach ($this->getProcessors(FALSE) as $processor_id => $processor) { - if ($processor->isLocked() && !isset($this->options['processors'][$processor_id])) { - $this->options['processors'][$processor_id] = array( + if ($processor->isLocked() && !isset($this->processors[$processor_id])) { + $this->processors[$processor_id] = array( 'processor_id' => $processor_id, 'weights' => array(), 'settings' => array(), @@ -1392,8 +1410,8 @@ class Index extends ConfigEntityBase implements IndexInterface { * The previous version of the index. */ protected function reactToProcessorChanges(IndexInterface $original) { - $original_settings = $original->getOption('processors', array()); - $new_settings = $this->getOption('processors', array()); + $original_settings = $original->getProcessorSettings(); + $new_settings = $this->getProcessorSettings(); // Only actually do something when the processor settings are changed. if ($original_settings != $new_settings) { diff --git a/src/Form/IndexProcessorsForm.php b/src/Form/IndexProcessorsForm.php index 783e99a..7b4d0ca 100644 --- a/src/Form/IndexProcessorsForm.php +++ b/src/Form/IndexProcessorsForm.php @@ -96,7 +96,7 @@ class IndexProcessorsForm extends EntityForm { $processors_by_stage[$stage] = $this->entity->getProcessorsByStage($stage, FALSE); } - $processor_settings = $this->entity->getOption('processors'); + $processor_settings = $this->entity->getProcessorSettings(); $form['#tree'] = TRUE; $form['#attached']['library'][] = 'search_api/drupal.search_api.index-active-formatters'; @@ -263,10 +263,10 @@ class IndexProcessorsForm extends EntityForm { // Sort the processors so we won't have unnecessary changes. ksort($new_settings); - $settings_changed = $new_settings != $this->entity->getOption('processors', array()); + $settings_changed = $new_settings != $this->entity->getProcessorSettings(); $form_state->set('processors_changed', $settings_changed); if ($settings_changed) { - $this->entity->setOption('processors', $new_settings); + $this->entity->setProcessorSettings($new_settings); } } diff --git a/src/IndexInterface.php b/src/IndexInterface.php index b5ccd54..78f9d3b 100644 --- a/src/IndexInterface.php +++ b/src/IndexInterface.php @@ -277,6 +277,23 @@ interface IndexInterface extends ConfigEntityInterface { public function getProcessorsByStage($stage, $only_enabled = TRUE); /** + * Sets processor settings. + * + * @param array $processors + * An array of processors and it's settings. + * @return $this + */ + public function setProcessorSettings(array $processors); + + /** + * Gets processor settings. + * + * @return array + * An array of processors and it's settings. + */ + public function getProcessorSettings(); + + /** * Preprocesses data items for indexing. * * Lets all enabled processors for this index preprocess the indexed data. diff --git a/src/Tests/HooksTest.php b/src/Tests/HooksTest.php index bc66fff..09d79ca 100644 --- a/src/Tests/HooksTest.php +++ b/src/Tests/HooksTest.php @@ -17,7 +17,13 @@ class HooksTest extends WebTestBase { /** * {@inheritdoc} */ - public static $modules = array('node', 'search_api', 'search_api_test_backend', 'search_api_test_views', 'search_api_test_hooks'); + public static $modules = array( + 'node', + 'search_api', + 'search_api_test_backend', + 'search_api_test_views', + 'search_api_test_hooks', + ); /** * The id of the index. diff --git a/src/Tests/Processor/ProcessorIntegrationTest.php b/src/Tests/Processor/ProcessorIntegrationTest.php index ac22441..d922462 100644 --- a/src/Tests/Processor/ProcessorIntegrationTest.php +++ b/src/Tests/Processor/ProcessorIntegrationTest.php @@ -134,10 +134,10 @@ class ProcessorIntegrationTest extends WebTestBase { */ public function checkLanguageIntegration() { $index = $this->loadIndex(); - $processors = $index->getOption('processors', array()); + $processors = $index->getProcessorSettings(); $this->assertTrue(!empty($processors['language']), 'The "language" processor is enabled by default.'); unset($processors['language']); - $index->setOption('processors', $processors)->save(); + $index->setProcessorSettings($processors)->save(); $processors = $this->loadIndex()->getProcessors(); $this->assertTrue(!empty($processors['language']), 'The "language" processor cannot be disabled.'); } diff --git a/src/Tests/Processor/ProcessorTestBase.php b/src/Tests/Processor/ProcessorTestBase.php index 64f9c22..57a9ed0 100644 --- a/src/Tests/Processor/ProcessorTestBase.php +++ b/src/Tests/Processor/ProcessorTestBase.php @@ -101,7 +101,7 @@ abstract class ProcessorTestBase extends EntityUnitTestBase { ), )); if ($processor) { - $this->index->setOption('processors', array( + $this->index->setProcessorSettings(array( $processor => array( 'processor_id' => $processor, 'weights' => array(),