diff --git a/search_api_db/src/Tests/BackendTest.php b/search_api_db/src/Tests/BackendTest.php index 5d863ad..3671af6 100644 --- a/search_api_db/src/Tests/BackendTest.php +++ b/search_api_db/src/Tests/BackendTest.php @@ -166,7 +166,7 @@ class BackendTest extends EntityUnitTestBase { $index->removeField('keywords'); $index->save(); - $index_fields = array_keys($index->getFieldSettings()); + $index_fields = array_keys($index->getFields()); $db_info = \Drupal::keyValue(BackendDatabase::INDEXES_KEY_VALUE_STORE_ID)->get($this->indexId); $server_fields = array_keys($db_info['field_tables']); diff --git a/src/Entity/Index.php b/src/Entity/Index.php index fcc019f..5e76b1a 100644 --- a/src/Entity/Index.php +++ b/src/Entity/Index.php @@ -206,15 +206,6 @@ class Index extends ConfigEntityBase implements IndexInterface { protected $cache = array(); /** - * Cached information about the processors available for this index. - * - * @var \Drupal\search_api\Processor\ProcessorInterface[]|null - * - * @see loadProcessors() - */ - protected $processorInstances; - - /** * The array of processor settings. * * @var array @@ -223,6 +214,15 @@ class Index extends ConfigEntityBase implements IndexInterface { protected $processors = array(); /** + * Cached information about the processors available for this index. + * + * @var \Drupal\search_api\Processor\ProcessorInterface[]|null + * + * @see loadProcessors() + */ + protected $processorPlugins; + + /** * Whether reindexing has been triggered for this index in this page request. * * @var bool @@ -277,8 +277,9 @@ class Index extends ConfigEntityBase implements IndexInterface { * {@inheritdoc} */ public function getOption($name, $default = NULL) { + // @todo Remove before stable release. if (in_array($name, array('fields', 'processors'))) { - throw new \Exception("Deprecated call, " . $name . " now has it's own getter and no longer belongs in options."); + throw new \UnexpectedValueException("Deprecated call, " . $name . " now has its own getter and no longer belongs in options."); } return isset($this->options[$name]) ? $this->options[$name] : $default; } @@ -294,8 +295,9 @@ class Index extends ConfigEntityBase implements IndexInterface { * {@inheritdoc} */ public function setOption($name, $option) { + // @todo Remove before stable release. if (in_array($name, array('fields', 'processors'))) { - throw new \Exception("Deprecated call, " . $name . " now has it's own setter and no longer belongs in options."); + throw new \UnexpectedValueException("Deprecated call, " . $name . " now has its own setter and no longer belongs in options."); } $this->options[$name] = $option; // If the fields are changed, reset the static fields cache. @@ -316,21 +318,6 @@ class Index extends ConfigEntityBase implements IndexInterface { /** * {@inheritdoc} */ - public function setFieldSettings(array $fields = array()) { - $this->fields = $fields; - return $this; - } - - /** - * {@inheritdoc} - */ - public function getFieldSettings() { - return $this->fields; - } - - /** - * {@inheritdoc} - */ public function getDatasourceIds() { return $this->datasources; } @@ -517,13 +504,13 @@ class Index extends ConfigEntityBase implements IndexInterface { * The loaded processors, keyed by processor ID. */ protected function loadProcessors() { - if (empty($this->processorInstances)) { + if (empty($this->processorPlugins)) { /** @var $processor_plugin_manager \Drupal\search_api\Processor\ProcessorPluginManager */ $processor_plugin_manager = \Drupal::service('plugin.manager.search_api.processor'); $processor_settings = $this->getProcessorSettings(); foreach ($processor_plugin_manager->getDefinitions() as $name => $processor_definition) { - if (class_exists($processor_definition['class']) && empty($this->processorInstances[$name])) { + if (class_exists($processor_definition['class']) && empty($this->processorPlugins[$name])) { // Create our settings for this processor. $settings = empty($processor_settings[$name]['settings']) ? array() : $processor_settings[$name]['settings']; $settings['index'] = $this; @@ -531,7 +518,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->processorInstances[$name] = $processor; + $this->processorPlugins[$name] = $processor; } } elseif (!class_exists($processor_definition['class'])) { @@ -540,26 +527,24 @@ class Index extends ConfigEntityBase implements IndexInterface { } } - return $this->processorInstances; + return $this->processorPlugins; } - /** * {@inheritdoc} */ - public function setProcessorSettings(array $processors) { - $this->processors = $processors; - return $this; + public function getProcessorSettings() { + return $this->processors; } /** * {@inheritdoc} */ - public function getProcessorSettings() { - return $this->processors; + public function setProcessorSettings(array $processors) { + $this->processors = $processors; + return $this; } - /** * {@inheritdoc} */ @@ -721,6 +706,21 @@ class Index extends ConfigEntityBase implements IndexInterface { /** * {@inheritdoc} */ + public function getFieldSettings() { + return $this->fields; + } + + /** + * {@inheritdoc} + */ + public function setFieldSettings(array $fields = array()) { + $this->fields = $fields; + return $this; + } + + /** + * {@inheritdoc} + */ public function getPropertyDefinitions($datasource_id, $alter = TRUE) { $alter = $alter ? 1 : 0; $properties = $this->getCache(__FUNCTION__); @@ -1035,7 +1035,7 @@ class Index extends ConfigEntityBase implements IndexInterface { $this->datasourcePlugins = NULL; $this->trackerPlugin = NULL; $this->serverInstance = NULL; - $this->processorInstances = NULL; + $this->processorPlugins = NULL; $this->properties = NULL; $this->cache = array(); if ($include_stored) { diff --git a/src/IndexInterface.php b/src/IndexInterface.php index e0a10f5..3d8fb82 100644 --- a/src/IndexInterface.php +++ b/src/IndexInterface.php @@ -260,24 +260,6 @@ interface IndexInterface extends ConfigEntityInterface { public function getProcessors($only_enabled = TRUE); /** - * Sets this index's processor settings. - * - * @param array $processors - * An array of processors and it's settings. - * - * @return $this - */ - public function setProcessorSettings(array $processors); - - /** - * Retrieves this index's processor settings. - * - * @return array - * An array of processors and it's settings. - */ - public function getProcessorSettings(); - - /** * Loads this index's processors for a specific stage. * * @param string $stage @@ -295,6 +277,24 @@ interface IndexInterface extends ConfigEntityInterface { public function getProcessorsByStage($stage, $only_enabled = TRUE); /** + * Retrieves this index's processor settings. + * + * @return array + * An array of processors and their settings. + */ + public function getProcessorSettings(); + + /** + * Sets this index's processor settings. + * + * @param array $processors + * An array of processors and their settings. + * + * @return $this + */ + public function setProcessorSettings(array $processors); + + /** * Preprocesses data items for indexing. * * Lets all enabled processors for this index preprocess the indexed data. @@ -386,24 +386,6 @@ interface IndexInterface extends ConfigEntityInterface { public function getFields(); /** - * Retrieves this index's field settings - * - * @return array - * An array of field settings - */ - public function getFieldSettings(); - - /** - * Sets this index's field settings - * - * @param array $fields - * An array of field settings. - * - * @return $this - */ - public function setFieldSettings(array $fields); - - /** * Returns a field from this index. * * @param string $field_id @@ -438,6 +420,24 @@ interface IndexInterface extends ConfigEntityInterface { public function getFulltextFields(); /** + * Retrieves this index's field settings. + * + * @return array + * An array of field settings. + */ + public function getFieldSettings(); + + /** + * Sets this index's field settings. + * + * @param array $fields + * An array of field settings. + * + * @return $this + */ + public function setFieldSettings(array $fields); + + /** * Retrieves the properties of one of this index's datasources. * * @param string|null $datasource_id diff --git a/src/Plugin/views/argument/SearchApiMoreLikeThis.php b/src/Plugin/views/argument/SearchApiMoreLikeThis.php index 0ec863d..f39c8b0 100644 --- a/src/Plugin/views/argument/SearchApiMoreLikeThis.php +++ b/src/Plugin/views/argument/SearchApiMoreLikeThis.php @@ -79,9 +79,7 @@ class SearchApiMoreLikeThis extends SearchApiArgument { } $fields = isset($this->options['fields']) ? $this->options['fields'] : array(); if (!$fields) { - foreach ($this->query->getIndex()->getFieldSettings() as $key => $field) { - $fields[] = $key; - } + $fields = array_keys($this->query->getIndex()->getFields()); } $mlt = array( 'id' => $this->argument,