diff --git a/src/Entity/Index.php b/src/Entity/Index.php index b58744b..444fbd1 100644 --- a/src/Entity/Index.php +++ b/src/Entity/Index.php @@ -360,7 +360,7 @@ class Index extends ConfigEntityBase implements IndexInterface { * {@inheritdoc} */ public function getTrackerId() { - return $this->getTrackerInstance()->getConfiguration()['plugin_id']; + return $this->getTrackerInstance()->getPluginId(); } /** @@ -375,12 +375,12 @@ class Index extends ConfigEntityBase implements IndexInterface { ); } else { - $tracker_settings = $this->tracker_settings[$this->getTrackerId()]; + $tracker_settings = reset($this->tracker_settings); } $tracker_plugin_configuration = array('index' => $this) + $tracker_settings['settings']; try { - $this->trackerInstance = \Drupal::service('plugin.manager.search_api.tracker')->createInstance($this->getTrackerId(), $tracker_plugin_configuration); + $this->trackerInstance = \Drupal::service('plugin.manager.search_api.tracker')->createInstance($tracker_settings['plugin_id'], $tracker_plugin_configuration); } catch (PluginException $pe) { $args['@tracker'] = $tracker_settings['plugin_id']; $args['%index'] = $this->label(); @@ -1222,8 +1222,18 @@ class Index extends ConfigEntityBase implements IndexInterface { * The previous version of the index. */ protected function reactToProcessorChanges(IndexInterface $original) { - $original_settings = $original->getProcessorSettings(); - $new_settings = $this->getProcessorSettings(); + $orginal_processors = $original->getProcessors(); + $new_processors = $this->getProcessors(); + + $new_settings = array(); + $original_settings = array(); + + foreach ($orginal_processors as $k => $processor) { + $original_settings[$k] = $processor->getConfiguration(); + } + foreach ($new_processors as $k => $processor) { + $new_settings[$k] = $processor->getConfiguration(); + } // Only actually do something when the processor settings are changed. if ($original_settings != $new_settings) { diff --git a/src/Item/Field.php b/src/Item/Field.php index 97637ad..abbe268 100644 --- a/src/Item/Field.php +++ b/src/Item/Field.php @@ -439,8 +439,7 @@ class Field implements \IteratorAggregate, FieldInterface { */ public function getBoost() { if (!isset($this->boost)) { - $fields = $this->index->getFieldSettings(); - $this->boost = isset($fields[$this->fieldIdentifier]['boost']) ? (float) $fields[$this->fieldIdentifier]['boost'] : 1.0; + $this->boost = 1.0; } return $this->boost; } diff --git a/src/Tests/Processor/ProcessorIntegrationTest.php b/src/Tests/Processor/ProcessorIntegrationTest.php index 92e590f..912e9e4 100644 --- a/src/Tests/Processor/ProcessorIntegrationTest.php +++ b/src/Tests/Processor/ProcessorIntegrationTest.php @@ -173,7 +173,7 @@ class ProcessorIntegrationTest extends WebTestBase { */ public function checkLanguageIntegration() { $index = $this->loadIndex(); - $processors = $index->getProcessorSettings(); + $processors = $index->getProcessors(); $this->assertTrue(!empty($processors['language']), 'The "language" processor is enabled by default.'); unset($processors['language']); $index->setProcessorSettings($processors)->save(); diff --git a/src/Tests/Processor/ProcessorTestBase.php b/src/Tests/Processor/ProcessorTestBase.php index abb60e6..cc93553 100644 --- a/src/Tests/Processor/ProcessorTestBase.php +++ b/src/Tests/Processor/ProcessorTestBase.php @@ -9,6 +9,7 @@ namespace Drupal\search_api\Tests\Processor; use Drupal\search_api\Entity\Index; use Drupal\search_api\Entity\Server; +use Drupal\search_api\Item\Field; use Drupal\search_api\Utility; use Drupal\system\Tests\Entity\EntityUnitTestBase; @@ -106,22 +107,23 @@ abstract class ProcessorTestBase extends EntityUnitTestBase { ), )); $this->index->setServer($this->server); - $this->index->setFieldSettings(array( - 'subject' => array( - 'label' => 'Subject', - 'type' => 'text', - 'datasource_id' => 'entity:comment', - 'property_path' => 'subject', - ), - 'title' => array( - 'label' => 'Title', - 'type' => 'text', - 'datasource_id' => 'entity:node', - 'property_path' => 'title', - ), - )); + + $subject_field = new Field($this->index, 'subject'); + $subject_field->setType('text'); + $subject_field->setLabel('Subject'); + $subject_field->setDatasourceId('entity:comment'); + $subject_field->setPropertyPath('subject'); + $this->index->addField($subject_field); + + $title_field = new Field($this->index, 'title'); + $title_field->setType('text'); + $title_field->setLabel('Title'); + $title_field->setDatasourceId('entity:node'); + $title_field->setPropertyPath('title'); + $this->index->addField($title_field); + if ($processor) { - $this->index->setProcessorSettings(array( + $this->index->set('processor_settings', array( $processor => array( 'plugin_id' => $processor, 'weights' => array(), diff --git a/src/Tests/Processor/RenderedItemTest.php b/src/Tests/Processor/RenderedItemTest.php index 8a920e4..20157c7 100644 --- a/src/Tests/Processor/RenderedItemTest.php +++ b/src/Tests/Processor/RenderedItemTest.php @@ -10,6 +10,7 @@ namespace Drupal\search_api\Tests\Processor; use Drupal\Core\TypedData\DataDefinition; use Drupal\node\Entity\Node; use Drupal\node\Entity\NodeType; +use Drupal\search_api\Item\FieldInterface; use Drupal\search_api\Utility; use Drupal\user\Entity\Role; use Drupal\user\Entity\User; @@ -115,6 +116,14 @@ class RenderedItemTest extends ProcessorTestBase { } /** + * Tests that the processor is added correctly. + */ + public function testAddProcessor() { + $processors = $this->index->getProcessors(); + $this->assertTrue(array_key_exists('rendered_item', $processors), 'Processor successfully added.'); + } + + /** * Tests whether the rendered_item field is correctly filled by the processor. */ public function testPreprocessIndexItems() {