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 5618afe..c5fba12 100644 --- a/search_api_db/src/Plugin/search_api/backend/Database.php +++ b/search_api_db/src/Plugin/search_api/backend/Database.php @@ -1287,7 +1287,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->getProcessors(FALSE)['search_api_tokenizer']->getConfiguration()['status'])) { + if (empty($index->getProcessors()['tokenizer'])) { $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/tests/src/Kernel/BackendTest.php b/search_api_db/tests/src/Kernel/BackendTest.php index 2b0d5f4..8e3d417 100644 --- a/search_api_db/tests/src/Kernel/BackendTest.php +++ b/search_api_db/tests/src/Kernel/BackendTest.php @@ -207,7 +207,7 @@ class BackendTest extends KernelTestBase { ->get('plugin.manager.search_api.processor') ->createInstance('html_filter'); - $index->addProcessor($processor, array()); + $index->addProcessor($processor); $index->save(); $this->assertArrayHasKey('html_filter', $index->getProcessors()); diff --git a/src/Entity/Index.php b/src/Entity/Index.php index 27bba55..bf01515 100644 --- a/src/Entity/Index.php +++ b/src/Entity/Index.php @@ -344,7 +344,7 @@ class Index extends ConfigEntityBase implements IndexInterface { return $this->datasourceInstances; } - return array_intersect_key($this->datasourceInstances, array_flip(array_keys($this->datasource_settings))); + return array_intersect_key($this->datasourceInstances, $this->datasource_settings); } /** @@ -484,15 +484,17 @@ class Index extends ConfigEntityBase implements IndexInterface { /** * {@inheritdoc} */ - public function addProcessor(ProcessorInterface $processor, array $settings = array()) { + public function addProcessor(ProcessorInterface $processor) { $this->processor_settings[$processor->getPluginId()] = array( 'plugin_id' => $processor->getPluginId(), 'weights' => array(), - 'settings' => $settings, + 'settings' => $processor->getConfiguration(), ); // Reset processors static cache. $this->processorInstances = array(); + + return $this; } /** @@ -503,6 +505,8 @@ class Index extends ConfigEntityBase implements IndexInterface { // Reset processors static cache. $this->processorInstances = array(); + + return $this; } /** @@ -1243,21 +1247,20 @@ class Index extends ConfigEntityBase implements IndexInterface { * The previous version of the index. */ protected function reactToProcessorChanges(IndexInterface $original) { - $original_settings = $original->getProcessors(); - $new_settings = $this->getProcessors(); + $old_processors = $original->getProcessors(); + $new_processors = $this->getProcessors(); // Only actually do something when the processor settings are changed. - if ($original_settings != $new_settings) { + if ($old_processors != $new_processors) { $requires_reindex = FALSE; - $processors = $this->getProcessors(FALSE); // Loop over all new settings and check if the processors were already set // in the original entity. - foreach ($new_settings as $key => $setting) { + foreach ($new_processors as $key => $processor) { // The processor is new, because it wasn't configured in the original // entity. - if (!isset($original_settings[$key])) { - if ($processors[$key]->requiresReindexing(NULL, $new_settings[$key]->getConfiguration())) { + if (!isset($old_processors[$key])) { + if ($processor->requiresReindexing(NULL, $processor->getConfiguration())) { $requires_reindex = TRUE; break; } @@ -1267,17 +1270,12 @@ class Index extends ConfigEntityBase implements IndexInterface { if (!$requires_reindex) { // Loop over all original settings and check if one of them has been // removed or changed. - foreach ($original_settings as $key => $old_processor_settings) { - // If the processor isn't even available any more, we can't determine - // what it would have said about the need to reindex. Err on the side - // of caution and guess "yes". - if (empty($processors[$key])) { - $requires_reindex = TRUE; - break; - } - $new_processor_settings = isset($new_settings[$key]) ? $new_settings[$key] : NULL; - if (!isset($new_processor_settings) || $new_processor_settings != $old_processor_settings) { - if ($processors[$key]->requiresReindexing($old_processor_settings->getConfiguration(), $new_processor_settings->getConfiguration())) { + foreach ($old_processors as $key => $old_processor) { + $new_processor = isset($new_processors[$key]) ? $new_processors[$key] : NULL; + $old_config = $old_processor->getConfiguration(); + $new_config = $new_processor ? $new_processor->getConfiguration() : NULL; + if (!$new_processor || $old_config != $new_config) { + if ($old_processor->requiresReindexing($old_config, $new_config)) { $requires_reindex = TRUE; break; } diff --git a/src/Form/IndexProcessorsForm.php b/src/Form/IndexProcessorsForm.php index 5cff142..c071098 100644 --- a/src/Form/IndexProcessorsForm.php +++ b/src/Form/IndexProcessorsForm.php @@ -281,7 +281,7 @@ class IndexProcessorsForm extends EntityForm { if (isset($old_processors[$plugin_id])) { $this->entity->removeProcessor($plugin_id); } - $this->entity->addProcessor($new_processor, $new_settings[$plugin_id]['settings']); + $this->entity->addProcessor($new_processor); } $new_processors = $this->entity->getProcessors(); diff --git a/src/IndexInterface.php b/src/IndexInterface.php index 39f05f2..72ecf87 100644 --- a/src/IndexInterface.php +++ b/src/IndexInterface.php @@ -278,20 +278,22 @@ interface IndexInterface extends ConfigEntityInterface { public function getProcessorsByStage($stage, $only_enabled = TRUE); /** - * Add a processor. + * Adds a processor to this index. * * @param \Drupal\search_api\Processor\ProcessorInterface $processor - * Processor to be added. - * @param array $settings - * Settings for the processor - * @return void + * The processor to be added. + * + * @return $this */ - public function addProcessor(ProcessorInterface $processor, array $settings = array()); + public function addProcessor(ProcessorInterface $processor); /** - * Remove processor + * Removes a processor from this index. * - * @param $processor_id + * @param string $processor_id + * The ID of the processor to remove. + * + * @return $this */ public function removeProcessor($processor_id); diff --git a/src/Tests/IntegrationTest.php b/src/Tests/IntegrationTest.php index a34e452..b639e9c 100644 --- a/src/Tests/IntegrationTest.php +++ b/src/Tests/IntegrationTest.php @@ -98,9 +98,9 @@ class IntegrationTest extends WebTestBase { } /** - * Test what happens when an index has an integer as id/label. + * Tests what happens when an index has an integer as id/label. * - * This needs to be in a seperate index because we also want to see what + * This needs to be in a separate index because we also want to see what * happens with the content and we don't want to mess with the content entity * tracking of the other index. */ diff --git a/src/Tests/Processor/ProcessorIntegrationTest.php b/src/Tests/Processor/ProcessorIntegrationTest.php index 334b43b..1be986d 100644 --- a/src/Tests/Processor/ProcessorIntegrationTest.php +++ b/src/Tests/Processor/ProcessorIntegrationTest.php @@ -102,7 +102,6 @@ class ProcessorIntegrationTest extends WebTestBase { $actual_processors = array_keys($this->loadIndex()->getProcessors()); $this->assertEqual(sort($enabled), sort($actual_processors)); - // The 'language' and 'add_url' processors are are not available to be removed $actual_processors = array_keys($this->loadIndex()->getProcessors()); $this->assertEqual(sort($enabled), sort($actual_processors)); diff --git a/src/Tests/Processor/ProcessorTestBase.php b/src/Tests/Processor/ProcessorTestBase.php index aa7bc3d..17d4932 100644 --- a/src/Tests/Processor/ProcessorTestBase.php +++ b/src/Tests/Processor/ProcessorTestBase.php @@ -122,7 +122,7 @@ abstract class ProcessorTestBase extends EntityUnitTestBase { /** @var \Drupal\search_api\Processor\ProcessorPluginManager $plugin_manager */ $plugin_manager = \Drupal::service('plugin.manager.search_api.processor'); $this->processor = $plugin_manager->createInstance($processor, array('index' => $this->index)); - $this->index->addProcessor($this->processor, array()); + $this->index->addProcessor($this->processor); } $this->index->save(); } diff --git a/tests/src/Kernel/DependencyRemovalTest.php b/tests/src/Kernel/DependencyRemovalTest.php index 978be7e..745f379 100644 --- a/tests/src/Kernel/DependencyRemovalTest.php +++ b/tests/src/Kernel/DependencyRemovalTest.php @@ -464,12 +464,12 @@ class DependencyRemovalTest extends KernelTestBase { * If $dependency_removal_return_value is TRUE, in * Plugin::onDependencyRemoval() it clears its configuration (and thus its * dependency, in those test plugins) and returns TRUE, which the index will - * take as "all OK, dependency removed" and leave the plugin where it is, - * only with updated configuration. + * take as "all OK, dependency removed" and leave the plugin where it is, only + * with updated configuration. * * If $dependency_removal_return_value is FALSE, Plugin::onDependencyRemoval() * will do nothing and just return FALSE, the index says "oh, that plugin - * still has that removed depenency, so I should better remove the plugin" + * still has that removed dependency, so I should better remove the plugin" * and the plugin gets removed. * * @return array @@ -477,8 +477,8 @@ class DependencyRemovalTest extends KernelTestBase { */ public function dependencyTestDataProvider() { return array( - 'Keep dependency' => array(TRUE), - 'Remove dependency' => array(FALSE), + 'Remove dependency' => array(TRUE), + 'Keep dependency' => array(FALSE), ); }