diff --git a/datasource.md b/datasource.md index 437cdf60..fcd19c46 100644 --- a/datasource.md +++ b/datasource.md @@ -1,14 +1,14 @@ 1. Add a Search API index for the server you configured in step 2. 1. Check "Solr Document" under the list of Data Sources. - 2. Configure the Solr Document Datasource by specifying the name of a unique ID - field from your server's schema. + 2. Configure the Solr Document Datasource by specifying the name of a unique + ID field from your server's schema. 3. Finish configuring the index by selecting the appropriate server. Check "Read only" under the Index Options. -2. On the index's Fields tab, add the fields you would like to have shown in Views - or any other display. Fields must be added here first before they can be - displayed, despite appearing in the Add fields list in Views. -3. Create a view or some other display to see the documents from your server. If - you are using Views, set it up as you would for any other Search API +2. On the index's Fields tab, add the fields you would like to have shown in + Views or any other display. Fields must be added here first before they can + be displayed, despite appearing in the Add fields list in Views. +3. Create a view or some other display to see the documents from your server. + If you are using Views, set it up as you would for any other Search API datasource. 1. In the Add view wizard, select "Index INDEX_NAME" under the View Settings. @@ -18,4 +18,5 @@ Known Issues ------------ * Search API Solr's backend unsets the ID field that you configure in the - datasource settings from the results arrays, making it unavailable for display. + datasource settings from the results arrays, making it unavailable for + display. diff --git a/modules/search_api_solr_devel/src/Commands/SearchApiSolrDevelCommands.php b/modules/search_api_solr_devel/src/Commands/SearchApiSolrDevelCommands.php index c3c23a78..c5045d88 100644 --- a/modules/search_api_solr_devel/src/Commands/SearchApiSolrDevelCommands.php +++ b/modules/search_api_solr_devel/src/Commands/SearchApiSolrDevelCommands.php @@ -7,7 +7,7 @@ use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\search_api\SearchApiException; use Drupal\search_api_solr\SearchApiSolrException; use Drupal\search_api_solr\SolrBackendInterface; -use Drupal\search_api_solr\Utility\CommandHelper; +use Drupal\search_api_solr\Utility\SolrCommandHelper; use Drush\Commands\DrushCommands; use Psr\Log\LoggerInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; @@ -20,7 +20,7 @@ class SearchApiSolrDevelCommands extends DrushCommands { /** * The command helper. * - * @var \Drupal\search_api_solr\Utility\CommandHelper + * @var \Drupal\search_api_solr\Utility\SolrCommandHelper */ protected $commandHelper; @@ -37,7 +37,7 @@ class SearchApiSolrDevelCommands extends DrushCommands { */ public function __construct(EntityTypeManagerInterface $entityTypeManager, ModuleHandlerInterface $moduleHandler, EventDispatcherInterface $eventDispatcher) { parent::__construct(); - $this->commandHelper = new CommandHelper($entityTypeManager, $moduleHandler, $eventDispatcher, 'dt'); + $this->commandHelper = new SolrCommandHelper($entityTypeManager, $moduleHandler, $eventDispatcher, 'dt'); } /** diff --git a/search_api_solr.install b/search_api_solr.install index bb5c59ad..5243623f 100644 --- a/search_api_solr.install +++ b/search_api_solr.install @@ -1,5 +1,10 @@ id() . '_languages']['severity'] = REQUIREMENT_WARNING; $requirements['search_api_solr_' . $server->id() . '_languages']['description'] = t( 'There are some language-specific field types missing in schema of Solr server @server: @languages.', [ - ':url' => $server->toUrl('canonical')->toString(), - '@server' => $server->label(), - '@languages' => implode(', ', array_keys($missing_languages)), - ]); + ':url' => $server->toUrl('canonical')->toString(), + '@server' => $server->label(), + '@languages' => implode(', ', array_keys($missing_languages)), + ] + ); } $config_set_controller = new SolrConfigSetController(); @@ -151,24 +159,26 @@ function search_api_solr_requirements($phase) { $requirements['search_api_solr_schema_' . $server->id() . '_modifications']['value'] = t('Schema not generated'); $requirements['search_api_solr_schema_' . $server->id() . '_modifications']['severity'] = REQUIREMENT_ERROR; - if ($e instanceof \Drupal\search_api_solr\SearchApiSolrConflictingEntitiesException) { + if ($e instanceof SearchApiSolrConflictingEntitiesException) { $requirements['search_api_solr_schema_' . $server->id() . '_modifications']['description'] = t( 'Some enabled parts of the configuration conflict with others: @conflicts', [ '@conflicts' => new FormattableMarkup(str_replace('core_issue_2919648_workaround', $server->id(), $e), []), - ]); + ] + ); } else { $requirements['search_api_solr_schema_' . $server->id() . '_modifications']['description'] = t( 'The config-set for the Solr server @server could not be generated.', [ - ':url' => $server->toUrl('canonical')->toString(), - '@server' => $server->label(), - ]); + ':url' => $server->toUrl('canonical')->toString(), + '@server' => $server->label(), + ] + ); } } if (!empty($new_config_set)) { $server_files_list = SearchApiSolrUtility::getServerFiles($server); - //the files that are already on the server + // The files that are already on the server. $server_file_names = array_keys($server_files_list); $new_config_file_names = array_keys($new_config_set); $extra_release_files = array_diff($new_config_file_names, $server_file_names); @@ -177,46 +187,48 @@ function search_api_solr_requirements($phase) { $requirements['search_api_solr_schema_' . $server->id() . '_modifications']['severity'] = REQUIREMENT_WARNING; $requirements['search_api_solr_schema_' . $server->id() . '_modifications']['description'] = t( 'There are some files missing in the Solr server schema @server: @files. An updated config.zip should be downloaded and deployed to your Solr server.', [ - ':url' => $server->toUrl('canonical')->toString(), - '@server' => $server->label(), - '@files' => implode(', ', array_keys($extra_release_files)), - ]); + ':url' => $server->toUrl('canonical')->toString(), + '@server' => $server->label(), + '@files' => implode(', ', array_keys($extra_release_files)), + ] + ); } foreach ($new_config_set as $new_file_name => $new_file_body) { if (stripos(strrev($new_file_name), 'lmx.') === 0) { try { $server_file_data = $connector->getFile($new_file_name); $server_file_body = $server_file_data->getBody(); - } catch (\Drupal\search_api_solr\SearchApiSolrException $e) { + } + catch (SearchApiSolrException $e) { $server_file_body = ''; } [ $version_number_server, - $xml_server - ] = SearchApiSolrUtility::normalizeXML($server_file_body); + $xml_server, + ] = SearchApiSolrUtility::normalizeXml($server_file_body); [ $version_number_new, - $xml_new - ] = SearchApiSolrUtility::normalizeXML($new_file_body); + $xml_new, + ] = SearchApiSolrUtility::normalizeXml($new_file_body); if (strcmp($xml_server, $xml_new) !== 0) { if ($version_number_server !== $version_number_new) { $requirements['search_api_solr_schema_' . $server->id() . '_modifications']['value'] = t('Schema not up to date'); $requirements['search_api_solr_schema_' . $server->id() . '_modifications']['severity'] = REQUIREMENT_ERROR; $requirements['search_api_solr_schema_' . $server->id() . '_modifications']['description'] = t( 'There are some configuration elements missing in the Solr server schema @server. This is likely due to using an outdated version of either Drupal or Solr. The recommended version is: @version. An updated config.zip should be downloaded and deployed to your Solr server.', [ - ':url' => $server->toUrl('canonical')->toString(), - '@server' => $server->label(), - '@version' => $version_number_new, - ]); + ':url' => $server->toUrl('canonical')->toString(), + '@server' => $server->label(), + '@version' => $version_number_new, + ] + ); break; } elseif ($version_number_server === $version_number_new) { $requirements['search_api_solr_schema_' . $server->id() . '_modifications']['value'] = t('Schema modified'); $requirements['search_api_solr_schema_' . $server->id() . '_modifications']['severity'] = REQUIREMENT_WARNING; $requirements['search_api_solr_schema_' . $server->id() . '_modifications']['description'] = t( - 'Your config-set contains manually added customizations. Be aware that these will be lost when the config-set needs to be regenerated.', [ - ]); + 'Your config-set contains manually added customizations. Be aware that these will be lost when the config-set needs to be regenerated.', []); } } } @@ -228,14 +240,15 @@ function search_api_solr_requirements($phase) { $requirements['search_api_solr_' . $server->id() . '_languages']['severity'] = REQUIREMENT_ERROR; $requirements['search_api_solr_' . $server->id() . '_languages']['description'] = t( 'Solr server @server is not reachable.', [ - ':url' => $server->toUrl('canonical')->toString(), - '@server' => $server->label(), - ]); + ':url' => $server->toUrl('canonical')->toString(), + '@server' => $server->label(), + ] + ); } } if (Client::checkMinimal('5.1.4')) { - $requirements['search_api_solr_' . 'solarium'] = [ + $requirements['search_api_solr_solarium'] = [ 'title' => t('solarium library'), 'value' => t('Up to date'), 'description' => t('Solarium @version is installed.', ['@version' => Client::VERSION]), @@ -243,7 +256,7 @@ function search_api_solr_requirements($phase) { ]; } else { - $requirements['search_api_solr_' . 'solarium'] = [ + $requirements['search_api_solr_solarium'] = [ 'title' => t('solarium library'), 'value' => t('Outdated'), 'description' => t('Solarium @version is too old and has known issues. In order to get composer to upgrade solarium to a recent version a core patch or a workaround is required. Have a look at this Core issue and this Search API Solr issue.', @@ -308,7 +321,9 @@ function search_api_solr_update_helper_get_backend_configs($pattern = 'solr') { * Saves a modified backend config for a given Solr server. * * @param string $server_name + * Name of the solr server. * @param array $backend_config + * Solr backend configuration. * @param bool $trusted_data */ function search_api_solr_update_helper_save_backend_config($server_name, array $backend_config, $trusted_data = TRUE) { @@ -343,6 +358,7 @@ function search_api_solr_update_helper_get_index_third_party_settings($pattern = * Saves a modified backend config for a given Solr server. * * @param string $index_id + * Id of the solr index. * @param array $third_party_settings * @param bool $trusted_data */ @@ -379,7 +395,8 @@ function search_api_solr_update_helper_get_indexes($pattern = 'solr') { * Saves a modified index config. * * @param string $index_id - * @param array $third_party_settings + * Id of the Solr Index. + * @param array $settings * @param bool $trusted_data */ function search_api_solr_update_helper_save_indexes($index_id, array $settings, $trusted_data = TRUE) { @@ -428,8 +445,8 @@ function search_api_solr_update_helper_install_configs($directory = InstallStora $config_installer->installDefaultConfig('module', 'search_api_solr'); $optional_install_path = \Drupal::moduleHandler() - ->getModule('search_api_solr') - ->getPath() . '/' . $directory; + ->getModule('search_api_solr') + ->getPath() . '/' . $directory; if (is_dir($optional_install_path)) { // Install any optional config the module provides. $storage = new FileStorage($optional_install_path, StorageInterface::DEFAULT_COLLECTION); @@ -488,19 +505,19 @@ function search_api_solr_update_8004() { $backend_config['connector'] = 'basic_auth'; $backend_config['connector_config'] = []; foreach ([ - 'scheme', - 'host', - 'port', - 'path', - 'core', - 'timeout', - 'index_timeout', - 'optimize_timeout', - 'solr_version', - 'http_method', - 'username', - 'password', - ] as $key) { + 'scheme', + 'host', + 'port', + 'path', + 'core', + 'timeout', + 'index_timeout', + 'optimize_timeout', + 'solr_version', + 'http_method', + 'username', + 'password', + ] as $key) { $backend_config['connector_config'][$key] = $backend_config[$key]; unset($backend_config[$key]); } @@ -562,7 +579,6 @@ function search_api_solr_update_8008() { function search_api_solr_update_8200() { // 8.x-1.x to 8.x-2.x migration path is obsolete and therefore removed. Just // install the latest field types. - \Drupal::entityDefinitionUpdateManager() ->installEntityType(new ConfigEntityType([ 'id' => 'solr_field_type', @@ -728,7 +744,6 @@ function search_api_solr_update_8208() { } // Removed search_api_solr_update_8209(). - // Removed search_api_solr_update_8210(). /** @@ -889,7 +904,7 @@ function search_api_solr_update_8302() { * Remove obsolete setting in config. */ function search_api_solr_update_8303() { - // obsolete because of search_api_solr_update_8304(). + // Obsolete because of search_api_solr_update_8304(). } /** @@ -969,9 +984,11 @@ function search_api_solr_update_8306() { case 'solr.WordDelimiterFilterFactory': $filter['class'] = 'solr.WordDelimiterGraphFilterFactory'; break; + case 'solr.SynonymFilterFactory': $filter['class'] = 'solr.SynonymGraphFilterFactory'; break; + case 'solr.StopFilterFactory': unset($filter['enablePositionIncrements']); break; @@ -1075,7 +1092,9 @@ function search_api_solr_update_8308() { } /** - * Solarium 5 adjustments. Warning! If you have overwritten the connection + * Solarium 5 adjustments. + * + * Warning! If you have overwritten the connection * settings, don't forget to adjust the 'path'. See the release notes for * details. */ @@ -1171,9 +1190,10 @@ function search_api_solr_update_8310() { } /** - * Add the Polish diacritics to the language configs. Unset the obsolete min and - * max parameters from the CJKWidthFilter of the spellchecker (mainly for - * Japanese). + * Add the Polish diacritics to the language configs. + * + * Unset the obsolete min and max parameters from the + * CJKWidthFilter of the spellchecker (mainly for Japanese). */ function search_api_solr_update_8311() { $accents = << $field_type_config) { if ('zh-hans' === $field_type_config['field_type_language_code']) { @@ -1316,6 +1336,8 @@ function search_api_solr_update_8314() { } /** + * Avoid Solr exceptions. + * * Avoid Solr exceptions when multilingual spell checking by using unified * analyzer. */ @@ -1397,7 +1419,6 @@ function search_api_solr_update_8317() { } } - /** * Replace solr.MorphologikFilterFactory by solr.MorfologikFilterFactory. */ @@ -1698,7 +1719,7 @@ function search_api_solr_update_8323() { * Install new Norwegian configs if required. */ function search_api_solr_update_8324() { - //search_api_solr_update_helper_install_configs(); + // search_api_solr_update_helper_install_configs(); } /** @@ -1732,8 +1753,7 @@ function search_api_solr_update_8325() { } /** - * Replace the solr.StempelPolishStemFilterFactory by the - * solr.MorfologikFilterFactory + * Replace the StempelPolishStemFilterFactory by the MorfologikFilterFactory. */ function search_api_solr_update_8326() { foreach (search_api_solr_update_helper_get_field_type_configs() as $field_type_name => $field_type_config) { @@ -1763,7 +1783,7 @@ function search_api_solr_update_8326() { } /** - * Update the Portuguese, Portugal config locale from 'pt' to 'pt-pt' + * Update the Portuguese, Portugal config locale from 'pt' to 'pt-pt'. */ function search_api_solr_update_8327() { foreach (search_api_solr_update_helper_get_field_type_configs() as $field_type_name => $field_type_config) { @@ -1775,7 +1795,7 @@ function search_api_solr_update_8327() { } } } - //search_api_solr_update_helper_install_configs(); + // search_api_solr_update_helper_install_configs(); } /** @@ -1783,7 +1803,6 @@ function search_api_solr_update_8327() { */ function search_api_solr_update_8328() { // search_api_solr_update_helper_install_configs(); - foreach (search_api_solr_update_helper_get_backend_configs() as $server_name => $backend_config) { if (!isset($backend_config['environment'])) { $backend_config['environment'] = 'default'; @@ -1913,7 +1932,8 @@ function search_api_solr_update_8331() { 'collection' => '/admin/config/search/search-api/server/{search_api_server}/solr_field_type', ], ])); - } else { + } + else { $entity_type = $manager->getEntityType('solr_field_type'); $entity_keys = $entity_type->get('entity_keys'); $entity_keys['disabled'] = 'disabled_field_types'; diff --git a/src/Commands/SearchApiSolrCommands.php b/src/Commands/SearchApiSolrCommands.php index 75348d6e..4924e898 100644 --- a/src/Commands/SearchApiSolrCommands.php +++ b/src/Commands/SearchApiSolrCommands.php @@ -10,7 +10,7 @@ use Drupal\search_api\ConsoleException; use Drupal\search_api_solr\SearchApiSolrException; use Drupal\search_api_solr\SolrBackendInterface; use Drupal\search_api_solr\SolrCloudConnectorInterface; -use Drupal\search_api_solr\Utility\CommandHelper; +use Drupal\search_api_solr\Utility\SolrCommandHelper; use Drush\Commands\DrushCommands; use Psr\Log\LoggerInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; @@ -25,7 +25,7 @@ class SearchApiSolrCommands extends DrushCommands implements StdinAwareInterface /** * The command helper. * - * @var \Drupal\search_api_solr\Utility\CommandHelper + * @var \Drupal\search_api_solr\Utility\SolrCommandHelper */ protected $commandHelper; @@ -37,13 +37,14 @@ class SearchApiSolrCommands extends DrushCommands implements StdinAwareInterface * @param \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler * The module handler. * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $eventDispatcher + * The event dispatcher. * * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException */ public function __construct(EntityTypeManagerInterface $entityTypeManager, ModuleHandlerInterface $moduleHandler, EventDispatcherInterface $eventDispatcher) { parent::__construct(); - $this->commandHelper = new CommandHelper($entityTypeManager, $moduleHandler, $eventDispatcher, 'dt'); + $this->commandHelper = new SolrCommandHelper($entityTypeManager, $moduleHandler, $eventDispatcher, 'dt'); } /** @@ -95,6 +96,14 @@ class SearchApiSolrCommands extends DrushCommands implements StdinAwareInterface * The file name of the config zip that should be created. * @param string $solr_version * The targeted Solr version. + * @param array $options + * Array with the Solr config. + * + * @throws \Drupal\search_api\ConsoleException + * @throws \Drupal\search_api\SearchApiException + * @throws \ZipStream\Exception\FileNotFoundException + * @throws \ZipStream\Exception\FileNotReadableException + * @throws \ZipStream\Exception\OverflowException * * @command search-api-solr:get-server-config * @@ -102,13 +111,8 @@ class SearchApiSolrCommands extends DrushCommands implements StdinAwareInterface * Get the config files for a solr server and save it as zip file. * * @aliases solr-gsc,sasm-gsc,search-api-solr-get-server-config,search-api-solr-multilingual-get-server-config - * - * @throws \Drupal\search_api\ConsoleException - * @throws \Drupal\search_api\SearchApiException - * @throws \ZipStream\Exception\FileNotFoundException - * @throws \ZipStream\Exception\FileNotReadableException */ - public function getServerConfig($server_id, $file_name = NULL, $solr_version = NULL, $options = []) { + public function getServerConfig($server_id, $file_name = NULL, $solr_version = NULL, array $options = []) { if (!$options['pipe'] && ($file_name == NULL)) { throw new ConsoleException('Required argument missing ("file_name"), and no --pipe option specified.'); } @@ -121,6 +125,8 @@ class SearchApiSolrCommands extends DrushCommands implements StdinAwareInterface * @param string $indexId * (optional) A search index ID, or NULL to index items for all enabled * indexes. + * @param array $options + * Array with the Solr config. * * @command search-api-solr:finalize-index * @@ -148,12 +154,13 @@ class SearchApiSolrCommands extends DrushCommands implements StdinAwareInterface /** * Executes a streaming expression from STDIN. * - * @command search-api-solr:execute-raw-streaming-expression - * * @param string $indexId * A search index ID. * @param mixed $expression * The streaming expression. Use '-' to read from STDIN. + * + * @command search-api-solr:execute-raw-streaming-expression + * * @usage drush search-api-solr:execute-streaming-expression node_index - < streaming_expression.txt * Execute the raw streaming expression in streaming_expression.txt * @@ -165,8 +172,7 @@ class SearchApiSolrCommands extends DrushCommands implements StdinAwareInterface * @throws \Drupal\search_api_solr\SearchApiSolrException * @throws \Drupal\search_api\SearchApiException */ - public function executeRawStreamingExpression($indexId, $expression) - { + public function executeRawStreamingExpression($indexId, $expression) { // Special flag indicating that the value has been passed via STDIN. if ($expression === '-') { $expression = $this->stdin()->contents(); @@ -209,4 +215,5 @@ class SearchApiSolrCommands extends DrushCommands implements StdinAwareInterface throw new SearchApiSolrException('Server could not be loaded.'); } + } diff --git a/src/Controller/AbstractSolrEntityController.php b/src/Controller/AbstractSolrEntityController.php index 080dd79a..cc595143 100644 --- a/src/Controller/AbstractSolrEntityController.php +++ b/src/Controller/AbstractSolrEntityController.php @@ -22,9 +22,11 @@ abstract class AbstractSolrEntityController extends ControllerBase { protected $messenger; /** + * Entity type id. + * * @var string */ - protected $entity_type_id; + protected $entityTypeId; /** * {@inheritdoc} @@ -75,7 +77,7 @@ abstract class AbstractSolrEntityController extends ControllerBase { */ protected function getListBuilder(ServerInterface $search_api_server) { /** @var \Drupal\search_api_solr\Controller\AbstractSolrEntityListBuilder $list_builder */ - $list_builder = $this->entityTypeManager()->getListBuilder($this->entity_type_id); + $list_builder = $this->entityTypeManager()->getListBuilder($this->entityTypeId); $list_builder->setServer($search_api_server); return $list_builder; } @@ -84,9 +86,12 @@ abstract class AbstractSolrEntityController extends ControllerBase { * Disables a Solr Entity on this server. * * @param \Drupal\search_api\ServerInterface $search_api_server + * Search API server. * @param \Drupal\search_api_solr\SolrConfigInterface $solr_entity + * Solr entity. * - * @return RedirectResponse + * @return \Symfony\Component\HttpFoundation\RedirectResponse + * Redirect response. * * @throws \Drupal\Core\Entity\EntityMalformedException * @throws \Drupal\Core\Entity\EntityStorageException @@ -105,9 +110,12 @@ abstract class AbstractSolrEntityController extends ControllerBase { * Enables a Solr Entity on this server. * * @param \Drupal\search_api\ServerInterface $search_api_server - * @param \Drupal\search_api_solr\SolrConfigInterface $solr_cache + * Search API server. + * @param \Drupal\search_api_solr\SolrConfigInterface $solr_entity + * Solr entity. * - * @return RedirectResponse + * @return \Symfony\Component\HttpFoundation\RedirectResponse + * Redirect response. * * @throws \Drupal\Core\Entity\EntityMalformedException * @throws \Drupal\Core\Entity\EntityStorageException diff --git a/src/Controller/AbstractSolrEntityListBuilder.php b/src/Controller/AbstractSolrEntityListBuilder.php index 2696f73c..0365221b 100644 --- a/src/Controller/AbstractSolrEntityListBuilder.php +++ b/src/Controller/AbstractSolrEntityListBuilder.php @@ -6,7 +6,7 @@ use Drupal\Core\Config\Entity\ConfigEntityListBuilder; use Drupal\Core\Entity\EntityInterface; use Drupal\search_api_solr\SearchApiSolrConflictingEntitiesException; use Drupal\search_api_solr\SearchApiSolrException; -use Drupal\search_api_solr\SolrConfigInterface; +use Drupal\search_api_solr\SolrCacheInterface; /** * Provides a listing of Solr Entities. @@ -16,16 +16,22 @@ abstract class AbstractSolrEntityListBuilder extends ConfigEntityListBuilder { use BackendTrait; /** + * The label. + * * @var string */ protected $label = ''; /** + * The option label. + * * @var string */ protected $option_label = 'Environment'; /** + * The default option. + * * @var string */ protected $default_option = 'default'; @@ -42,9 +48,9 @@ abstract class AbstractSolrEntityListBuilder extends ConfigEntityListBuilder { */ public function buildHeader() { $header = [ - 'label' => $this->t($this->label), + 'label' => $this->t('@label', ['@before' => $this->label]), 'minimum_solr_version' => $this->t('Minimum Solr Version'), - 'option' => $this->t($this->option_label), + 'option' => $this->t('@optionLabel', ['@optionLabel' => $this->option_label]), 'id' => $this->t('Machine name'), 'enabled' => $this->t('Enabled'), ]; @@ -55,7 +61,7 @@ abstract class AbstractSolrEntityListBuilder extends ConfigEntityListBuilder { * {@inheritdoc} */ public function buildRow(EntityInterface $solr_entity) { - /** @var SolrConfigInterface $solr_entity */ + /** @var \Drupal\search_api_solr\SolrConfigInterface $solr_entity */ $options = $solr_entity->getOptions(); if (empty($options)) { $options = [$this->default_option]; @@ -89,13 +95,14 @@ abstract class AbstractSolrEntityListBuilder extends ConfigEntityListBuilder { * Returns a list of all enabled caches for current server. * * @return array + * An array of all enabled caches for current server. * - * @throws SearchApiSolrConflictingEntitiesException + * @throws \Drupal\search_api_solr\SearchApiSolrConflictingEntitiesException * @throws \Drupal\search_api\SearchApiException */ public function getEnabledEntities(): array { $solr_entities = []; - /** @var SolrConfigInterface[] $entities */ + /** @var \Drupal\search_api_solr\SolrConfigInterface[] $entities */ $entities = $this->load(); foreach ($this->load() as $solr_entity) { if (!$solr_entity->disabledOnServer) { @@ -118,7 +125,7 @@ abstract class AbstractSolrEntityListBuilder extends ConfigEntityListBuilder { * @throws \Drupal\Core\Entity\EntityMalformedException */ public function getDefaultOperations(EntityInterface $solr_entity) { - /** @var SolrConfigInterface $solr_entity */ + /** @var \Drupal\search_api_solr\SolrConfigInterface $solr_entity */ $operations = parent::getDefaultOperations($solr_entity); unset($operations['delete']); @@ -141,6 +148,9 @@ abstract class AbstractSolrEntityListBuilder extends ConfigEntityListBuilder { return $operations; } + /** + * Get all disabled entities. + */ abstract protected function getDisabledEntities() : array; /** @@ -200,7 +210,8 @@ abstract class AbstractSolrEntityListBuilder extends ConfigEntityListBuilder { else { $name = $entity->getName(); if (isset($selection[$name])) { - // The more specific environment has precedence over a newer version. + // The more specific environment has precedence + // over a newer version. if ( // Current selection environment is 'default' but something more // specific is found. @@ -232,7 +243,7 @@ abstract class AbstractSolrEntityListBuilder extends ConfigEntityListBuilder { } if ($warning) { - $this->assumed_minimum_version = array_reduce($selection, function ($version, $item) { + $this->assumedMinimumVersion = array_reduce($selection, function ($version, $item) { if (version_compare($item['version'], $version, '<')) { return $item['version']; } @@ -242,7 +253,7 @@ abstract class AbstractSolrEntityListBuilder extends ConfigEntityListBuilder { \Drupal::messenger()->addWarning( $this->t( 'Unable to reach the Solr server (yet). Therefore the lowest supported Solr version %version is assumed. Once the connection works and the real Solr version could be detected it might be necessary to deploy an adjusted config to the server to get the best search results. If the server does not start using the downloadable config, you should edit the server and manually set the Solr version override temporarily that fits your server best and download the config again. But it is recommended to remove this override once the server is running.', - ['%version' => $this->assumed_minimum_version]) + ['%version' => $this->assumedMinimumVersion]) ); } @@ -256,10 +267,14 @@ abstract class AbstractSolrEntityListBuilder extends ConfigEntityListBuilder { } /** + * Merge two Solr cache entities. + * * @param \Drupal\search_api_solr\SolrCacheInterface $target + * The target Solr cache entity. * @param \Drupal\search_api_solr\SolrCacheInterface $source + * The source Solr cache entity. */ - protected function mergeSolrConfigs($target, $source) { + protected function mergeSolrConfigs(SolrCacheInterface $target, SolrCacheInterface $source) { if (empty($target->getSolrConfigs()) && !empty($source->getSolrConfigs())) { $target->setSolrConfigs($source->getSolrConfigs()); } @@ -268,6 +283,9 @@ abstract class AbstractSolrEntityListBuilder extends ConfigEntityListBuilder { /** * Returns the formatted XML for the entities. * + * @return string + * The formatted XML for the entities. + * * @throws \Drupal\search_api\SearchApiException */ public function getXml() { @@ -283,7 +301,11 @@ abstract class AbstractSolrEntityListBuilder extends ConfigEntityListBuilder { } /** + * Get all recommended Entities. + * * @return array + * An array of all recommended entities. + * * @throws \Drupal\search_api\SearchApiException */ public function getRecommendedEntities(): array { @@ -297,7 +319,11 @@ abstract class AbstractSolrEntityListBuilder extends ConfigEntityListBuilder { } /** + * Get all not recommended entities. + * * @return array + * An array of all not recommended entities. + * * @throws \Drupal\search_api\SearchApiException */ public function getNotRecommendedEntities(): array { @@ -311,7 +337,10 @@ abstract class AbstractSolrEntityListBuilder extends ConfigEntityListBuilder { } /** + * Get all recommended entities. + * * @return array + * An array of all recommended entities. */ public function getAllRecommendedEntities(): array { $entities = ConfigEntityListBuilder::load(); @@ -324,7 +353,10 @@ abstract class AbstractSolrEntityListBuilder extends ConfigEntityListBuilder { } /** + * Get all not recommended entities. + * * @return array + * An array of all not recommended entities. */ public function getAllNotRecommendedEntities(): array { $entities = ConfigEntityListBuilder::load(); @@ -337,7 +369,10 @@ abstract class AbstractSolrEntityListBuilder extends ConfigEntityListBuilder { } /** + * Get all conflicting entities. + * * @return array + * An array of all conflicting entities. */ public function getConflictingEntities(array $entities): array { $conflicting_entities = []; diff --git a/src/Controller/BackendTrait.php b/src/Controller/BackendTrait.php index 33e39609..c43de223 100644 --- a/src/Controller/BackendTrait.php +++ b/src/Controller/BackendTrait.php @@ -29,9 +29,11 @@ trait BackendTrait { * * @var string */ - protected $assumed_minimum_version = ''; + protected $assumedMinimumVersion = ''; /** + * Reset. + * * @var bool */ protected $reset = FALSE; @@ -45,7 +47,7 @@ trait BackendTrait { * @throws \Drupal\search_api\SearchApiException */ public function setServer(ServerInterface $server) { - /** @var SolrBackendInterface $backend */ + /* @var SolrBackendInterface $backend */ $backend = $server->getBackend(); $this->setBackend($backend); $this->serverId = $server->id(); @@ -72,7 +74,14 @@ trait BackendTrait { return $this->backend; } - public function setAssumedMinimumVersion(string $assumed_minimum_version) { - $this->assumed_minimum_version = $assumed_minimum_version; + /** + * Set assumed minimum version. + * + * @param \Drupal\search_api_solr\Controller\string $assumedMinimumVersion + * Assumed minimum version. + */ + public function setAssumedMinimumVersion(string $assumedMinimumVersion) { + $this->assumedMinimumVersion = $assumedMinimumVersion; } + } diff --git a/src/Controller/SolrCacheController.php b/src/Controller/SolrCacheController.php index 1d04da52..a847e665 100644 --- a/src/Controller/SolrCacheController.php +++ b/src/Controller/SolrCacheController.php @@ -4,7 +4,6 @@ namespace Drupal\search_api_solr\Controller; use Drupal\search_api\ServerInterface; use Drupal\search_api_solr\SolrConfigInterface; -use Symfony\Component\HttpFoundation\RedirectResponse; /** * Provides different listings of SolrCache. @@ -12,17 +11,22 @@ use Symfony\Component\HttpFoundation\RedirectResponse; class SolrCacheController extends AbstractSolrEntityController { /** + * Entity type id. + * * @var string */ - protected $entity_type_id = 'solr_cache'; + protected $entityTypeId = 'solr_cache'; /** * Disables a Solr Entity on this server. * * @param \Drupal\search_api\ServerInterface $search_api_server + * Search API server. * @param \Drupal\search_api_solr\SolrConfigInterface $solr_cache + * Solr cache. * - * @return RedirectResponse + * @return \Symfony\Component\HttpFoundation\RedirectResponse + * Redirect response. * * @throws \Drupal\Core\Entity\EntityStorageException */ @@ -34,9 +38,12 @@ class SolrCacheController extends AbstractSolrEntityController { * Enables a Solr Entity on this server. * * @param \Drupal\search_api\ServerInterface $search_api_server + * Search API server. * @param \Drupal\search_api_solr\SolrConfigInterface $solr_cache + * Solr cache. * - * @return RedirectResponse + * @return \Symfony\Component\HttpFoundation\RedirectResponse + * Redirect response. * * @throws \Drupal\Core\Entity\EntityStorageException */ diff --git a/src/Controller/SolrCacheListBuilder.php b/src/Controller/SolrCacheListBuilder.php index 6571bbc6..ca1d2823 100644 --- a/src/Controller/SolrCacheListBuilder.php +++ b/src/Controller/SolrCacheListBuilder.php @@ -8,6 +8,8 @@ namespace Drupal\search_api_solr\Controller; class SolrCacheListBuilder extends AbstractSolrEntityListBuilder { /** + * Cache label. + * * @var string */ protected $label = 'Solr Cache'; @@ -16,6 +18,8 @@ class SolrCacheListBuilder extends AbstractSolrEntityListBuilder { * Returns a list of all disabled caches for current server. * * @return array + * List of all disabled caches for current server. + * * @throws \Drupal\search_api\SearchApiException */ protected function getDisabledEntities(): array { diff --git a/src/Controller/SolrConfigSetController.php b/src/Controller/SolrConfigSetController.php index 352ed6a5..5890568d 100644 --- a/src/Controller/SolrConfigSetController.php +++ b/src/Controller/SolrConfigSetController.php @@ -23,10 +23,11 @@ class SolrConfigSetController extends ControllerBase { /** * Provides an XML snippet containing all extra Solr field types. * - * @param \Drupal\search_api\ServerInterface $search_api_server + * @param \Drupal\search_api\ServerInterface|null $search_api_server * The Search API server entity. * * @return string + * XML snippet containing all extra Solr field types. * * @throws \Drupal\search_api\SearchApiException */ @@ -61,10 +62,11 @@ class SolrConfigSetController extends ControllerBase { /** * Provides an XML snippet containing all extra Solr fields. * - * @param \Drupal\search_api\ServerInterface $search_api_server + * @param \Drupal\search_api\ServerInterface|null $search_api_server * The Search API server entity. * * @return string + * XML snippet containing all extra Solr fields. * * @throws \Drupal\search_api\SearchApiException */ @@ -98,10 +100,11 @@ class SolrConfigSetController extends ControllerBase { /** * Provides an XML snippet containing all extra solrconfig. * - * @param \Drupal\search_api\ServerInterface $search_api_server + * @param \Drupal\search_api\ServerInterface|null $search_api_server * The Search API server entity. * * @return string + * XML snippet containing all extra solrconfig. * * @throws \Drupal\search_api\SearchApiException */ @@ -139,10 +142,11 @@ class SolrConfigSetController extends ControllerBase { /** * Provides an XML snippet containing all query cache settings as XML. * - * @param \Drupal\search_api\ServerInterface $search_api_server + * @param \Drupal\search_api\ServerInterface|null $search_api_server * The Search API server entity. * * @return string + * XML snippet containing all query cache settings. * * @throws \Drupal\search_api\SearchApiException */ @@ -176,10 +180,11 @@ class SolrConfigSetController extends ControllerBase { /** * Provides an XML snippet containing all request dispatcher settings as XML. * - * @param \Drupal\search_api\ServerInterface $search_api_server + * @param \Drupal\search_api\ServerInterface|null $search_api_server * The Search API server entity. * * @return string + * The XML snippet containing all request dispatcher settings. * * @throws \Drupal\search_api\SearchApiException */ @@ -222,7 +227,7 @@ class SolrConfigSetController extends ControllerBase { /** @var \Drupal\search_api_solr\SolrBackendInterface $backend */ $backend = $this->getBackend(); $connector = $backend->getSolrConnector(); - $solr_branch = $real_solr_branch = $connector->getSolrBranch($this->assumed_minimum_version); + $solr_branch = $real_solr_branch = $connector->getSolrBranch($this->assumedMinimumVersion); // Solr 8.x uses the same schema and solrconf as 7.x. So we can use the same // templates and only adjust luceneMatchVersion to 8. @@ -258,7 +263,7 @@ class SolrConfigSetController extends ControllerBase { } } - $solrcore_properties['solr.luceneMatchVersion'] = $connector->getLuceneMatchVersion($this->assumed_minimum_version ?: ''); + $solrcore_properties['solr.luceneMatchVersion'] = $connector->getLuceneMatchVersion($this->assumedMinimumVersion ?: ''); // @todo // $solrcore_properties['solr.replication.masterUrl'] $solrcore_properties_string = ''; @@ -293,6 +298,7 @@ class SolrConfigSetController extends ControllerBase { * Returns a ZipStream of all configuration files. * * @param \ZipStream\Option\Archive $archive_options + * Archive options. * * @return \ZipStream\ZipStream * The ZipStream that contains all configuration files. @@ -305,7 +311,7 @@ class SolrConfigSetController extends ControllerBase { /** @var \Drupal\search_api_solr\SolrBackendInterface $backend */ $backend = $this->getBackend(); $connector = $backend->getSolrConnector(); - $solr_branch = $connector->getSolrBranch($this->assumed_minimum_version); + $solr_branch = $connector->getSolrBranch($this->assumedMinimumVersion); $zip = new ZipStream('solr_' . $solr_branch . '_config.zip', $archive_options); @@ -361,13 +367,13 @@ class SolrConfigSetController extends ControllerBase { /** * Provides an XML snippet containing all query cache settings as XML. * - * @param \Drupal\search_api\ServerInterface $search_api_server - * The Search API server entity. + * @param \Drupal\search_api_solr\Controller\string $file_name + * The file name. + * @param \Drupal\search_api_solr\Controller\string $xml + * The XML. * * @return \Symfony\Component\HttpFoundation\Response * The HTTP response object. - * - * @throws \Drupal\search_api\SearchApiException */ protected function streamXml(string $file_name, string $xml): Response { return new Response( @@ -384,9 +390,12 @@ class SolrConfigSetController extends ControllerBase { * Returns a ListBuilder. * * @param string $entity_type_id + * Entity type id. * @param \Drupal\search_api\ServerInterface|null $search_api_server + * Search API Server. * * @return \Drupal\search_api_solr\Controller\AbstractSolrEntityListBuilder + * A ListBuilder. * * @throws \Drupal\search_api\SearchApiException */ @@ -395,7 +404,8 @@ class SolrConfigSetController extends ControllerBase { $list_builder = $this->entityTypeManager()->getListBuilder($entity_type_id); if ($search_api_server) { $list_builder->setServer($search_api_server); - } else { + } + else { $list_builder->setBackend($this->getBackend()); } return $list_builder; diff --git a/src/Controller/SolrFieldTypeController.php b/src/Controller/SolrFieldTypeController.php index fd6f3f5f..7bbdf16e 100644 --- a/src/Controller/SolrFieldTypeController.php +++ b/src/Controller/SolrFieldTypeController.php @@ -4,7 +4,6 @@ namespace Drupal\search_api_solr\Controller; use Drupal\search_api\ServerInterface; use Drupal\search_api_solr\SolrConfigInterface; -use Symfony\Component\HttpFoundation\RedirectResponse; use ZipStream\Option\Archive; /** @@ -13,9 +12,11 @@ use ZipStream\Option\Archive; class SolrFieldTypeController extends AbstractSolrEntityController { /** + * Entity type id. + * * @var string */ - protected $entity_type_id = 'solr_field_type'; + protected $entityTypeId = 'solr_field_type'; /** * Provides a zip archive containing a complete Solr configuration. @@ -54,9 +55,12 @@ class SolrFieldTypeController extends AbstractSolrEntityController { * Disables a Solr Entity on this server. * * @param \Drupal\search_api\ServerInterface $search_api_server + * Search API server. * @param \Drupal\search_api_solr\SolrConfigInterface $solr_field_type + * Solr field type. * - * @return RedirectResponse + * @return \Symfony\Component\HttpFoundation\RedirectResponse + * Redirect response. * * @throws \Drupal\Core\Entity\EntityStorageException */ @@ -68,9 +72,12 @@ class SolrFieldTypeController extends AbstractSolrEntityController { * Enables a Solr Entity on this server. * * @param \Drupal\search_api\ServerInterface $search_api_server + * Search API server. * @param \Drupal\search_api_solr\SolrConfigInterface $solr_field_type + * Solr field type. * - * @return RedirectResponse + * @return \Symfony\Component\HttpFoundation\RedirectResponse + * Redirect response. * * @throws \Drupal\Core\Entity\EntityStorageException */ diff --git a/src/Controller/SolrFieldTypeListBuilder.php b/src/Controller/SolrFieldTypeListBuilder.php index 43a82434..50241cab 100644 --- a/src/Controller/SolrFieldTypeListBuilder.php +++ b/src/Controller/SolrFieldTypeListBuilder.php @@ -5,6 +5,7 @@ namespace Drupal\search_api_solr\Controller; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Language\LanguageInterface; use Drupal\search_api_solr\SearchApiSolrException; +use Drupal\search_api_solr\SolrFieldTypeInterface; /** * Provides a listing of SolrFieldType. @@ -78,7 +79,7 @@ class SolrFieldTypeListBuilder extends AbstractSolrEntityListBuilder { // returns as we provide language fallbacks. For example, 'de' should be // used for 'de-at' if there's no dedicated 'de-at' field type. array_walk($active_languages, function (&$value) { - list($value, ) = explode('-', $value); + list($value,) = explode('-', $value); }); $active_languages[] = LanguageInterface::LANGCODE_NOT_SPECIFIED; @@ -121,7 +122,7 @@ class SolrFieldTypeListBuilder extends AbstractSolrEntityListBuilder { /** @var \Drupal\search_api_solr\SolrFieldTypeInterface $solr_field_type */ $version = $solr_field_type->getMinimumSolrVersion(); $domains = $solr_field_type->getDomains(); - list($language, ) = explode('-', $solr_field_type->getFieldTypeLanguageCode()); + list($language,) = explode('-', $solr_field_type->getFieldTypeLanguageCode()); if ( $solr_field_type->requiresManagedSchema() != $this->getBackend()->isManagedSchema() || version_compare($version, $solr_version, '>') || @@ -165,7 +166,7 @@ class SolrFieldTypeListBuilder extends AbstractSolrEntityListBuilder { } if ($warning) { - $this->assumed_minimum_version = array_reduce($selection, function ($version, $item) { + $this->assumedMinimumVersion = array_reduce($selection, function ($version, $item) { if (version_compare($item['version'], $version, '<')) { return $item['version']; } @@ -175,7 +176,7 @@ class SolrFieldTypeListBuilder extends AbstractSolrEntityListBuilder { \Drupal::messenger()->addWarning( $this->t( 'Unable to reach the Solr server (yet). Therefore the lowest supported Solr version %version is assumed. Once the connection works and the real Solr version could be detected it might be necessary to deploy an adjusted config to the server to get the best search results. If the server does not start using the downloadable config, you should edit the server and manually set the Solr version override temporarily that fits your server best and download the config again. But it is recommended to remove this override once the server is running.', - ['%version' => $this->assumed_minimum_version]) + ['%version' => $this->assumedMinimumVersion]) ); } @@ -192,6 +193,8 @@ class SolrFieldTypeListBuilder extends AbstractSolrEntityListBuilder { * Returns a list of all disabled request handlers for current server. * * @return array + * A list of all disabled request handlers for current server. + * * @throws \Drupal\search_api\SearchApiException */ protected function getDisabledEntities(): array { @@ -201,10 +204,14 @@ class SolrFieldTypeListBuilder extends AbstractSolrEntityListBuilder { } /** + * Merge two Solr field type entities. + * * @param \Drupal\search_api_solr\SolrFieldTypeInterface $target + * The target Solr field type entity. * @param \Drupal\search_api_solr\SolrFieldTypeInterface $source + * The source Solr field type entity. */ - protected function mergeFieldTypes($target, $source) { + protected function mergeFieldTypes(SolrFieldTypeInterface $target, SolrFieldTypeInterface $source) { if (empty($target->getCollatedFieldType()) && !empty($source->getCollatedFieldType())) { $target->setCollatedFieldType($source->getCollatedFieldType()); } @@ -246,12 +253,12 @@ class SolrFieldTypeListBuilder extends AbstractSolrEntityListBuilder { */ public function getSchemaExtraFieldsXml() { $xml = ''; - /** @var \Drupal\search_api_solr\SolrFieldTypeInterface $solr_field_type */ + /* @var \Drupal\search_api_solr\SolrFieldTypeInterface $solr_field_type */ foreach ($this->getEnabledEntities() as $solr_field_type) { foreach ($solr_field_type->getStaticFields() as $static_field) { $xml .= ' $value) { - /** @noinspection NestedTernaryOperatorInspection */ + /* @noinspection NestedTernaryOperatorInspection */ $xml .= $attribute . '="' . (is_bool($value) ? ($value ? 'true' : 'false') : $value) . '" '; } $xml .= "/>\n"; @@ -259,7 +266,7 @@ class SolrFieldTypeListBuilder extends AbstractSolrEntityListBuilder { foreach ($solr_field_type->getDynamicFields() as $dynamic_field) { $xml .= ' $value) { - /** @noinspection NestedTernaryOperatorInspection */ + /* @noinspection NestedTernaryOperatorInspection */ $xml .= $attribute . '="' . (is_bool($value) ? ($value ? 'true' : 'false') : $value) . '" '; } $xml .= "/>\n"; @@ -268,7 +275,7 @@ class SolrFieldTypeListBuilder extends AbstractSolrEntityListBuilder { foreach ($solr_field_type->getCopyFields() as $copy_field) { $xml .= ' $value) { - /** @noinspection NestedTernaryOperatorInspection */ + /* @noinspection NestedTernaryOperatorInspection */ $xml .= $attribute . '="' . (is_bool($value) ? ($value ? 'true' : 'false') : $value) . '" '; } $xml .= "/>\n"; diff --git a/src/Controller/SolrRequestDispatcherController.php b/src/Controller/SolrRequestDispatcherController.php index d4c0af7e..bc9ca5c8 100644 --- a/src/Controller/SolrRequestDispatcherController.php +++ b/src/Controller/SolrRequestDispatcherController.php @@ -4,7 +4,6 @@ namespace Drupal\search_api_solr\Controller; use Drupal\search_api\ServerInterface; use Drupal\search_api_solr\SolrConfigInterface; -use Symfony\Component\HttpFoundation\RedirectResponse; /** * Provides different listings of SolrRequestDispatcher. @@ -12,17 +11,22 @@ use Symfony\Component\HttpFoundation\RedirectResponse; class SolrRequestDispatcherController extends AbstractSolrEntityController { /** + * Entity type id. + * * @var string */ - protected $entity_type_id = 'solr_request_dispatcher'; + protected $entityTypeId = 'solr_request_dispatcher'; /** * Disables a Solr Entity on this server. * * @param \Drupal\search_api\ServerInterface $search_api_server + * Search API server. * @param \Drupal\search_api_solr\SolrConfigInterface $solr_request_dispatcher + * Solr request dispatcher. * - * @return RedirectResponse + * @return \Symfony\Component\HttpFoundation\RedirectResponse + * Redirect response. * * @throws \Drupal\Core\Entity\EntityStorageException */ @@ -34,13 +38,17 @@ class SolrRequestDispatcherController extends AbstractSolrEntityController { * Enables a Solr Entity on this server. * * @param \Drupal\search_api\ServerInterface $search_api_server + * Serach API server. * @param \Drupal\search_api_solr\SolrConfigInterface $solr_request_dispatcher + * Solr request dispatcher. * - * @return RedirectResponse + * @return \Symfony\Component\HttpFoundation\RedirectResponse + * Redirect response. * * @throws \Drupal\Core\Entity\EntityStorageException */ public function enableOnServer(ServerInterface $search_api_server, SolrConfigInterface $solr_request_dispatcher) { return parent::enableOnServer($search_api_server, $solr_request_dispatcher); } + } diff --git a/src/Controller/SolrRequestDispatcherListBuilder.php b/src/Controller/SolrRequestDispatcherListBuilder.php index 0b5825e8..39afd0d9 100644 --- a/src/Controller/SolrRequestDispatcherListBuilder.php +++ b/src/Controller/SolrRequestDispatcherListBuilder.php @@ -8,6 +8,8 @@ namespace Drupal\search_api_solr\Controller; class SolrRequestDispatcherListBuilder extends AbstractSolrEntityListBuilder { /** + * Request dispatcher label. + * * @var string */ protected $label = 'Solr Request Dispatcher'; @@ -16,6 +18,8 @@ class SolrRequestDispatcherListBuilder extends AbstractSolrEntityListBuilder { * Returns a list of all disabled request handlers for current server. * * @return array + * List of all disabled request handlers for current server. + * * @throws \Drupal\search_api\SearchApiException */ protected function getDisabledEntities(): array { diff --git a/src/Controller/SolrRequestHandlerController.php b/src/Controller/SolrRequestHandlerController.php index 0c6dc1b3..7774a353 100644 --- a/src/Controller/SolrRequestHandlerController.php +++ b/src/Controller/SolrRequestHandlerController.php @@ -4,23 +4,29 @@ namespace Drupal\search_api_solr\Controller; use Drupal\search_api\ServerInterface; use Drupal\search_api_solr\SolrConfigInterface; -use Symfony\Component\HttpFoundation\RedirectResponse; /** * Provides different listings of SolrRequestHandler. */ class SolrRequestHandlerController extends AbstractSolrEntityController { + /** + * Entity type id. + * * @var string */ - protected $entity_type_id = 'solr_request_handler'; + protected $entityTypeId = 'solr_request_handler'; /** * Disables a Solr Entity on this server. * * @param \Drupal\search_api\ServerInterface $search_api_server + * Search API server. * @param \Drupal\search_api_solr\SolrConfigInterface $solr_request_handler - * @return RedirectResponse + * Solr request handler. + * + * @return \Symfony\Component\HttpFoundation\RedirectResponse + * Redirect response. * * @throws \Drupal\Core\Entity\EntityStorageException */ @@ -32,9 +38,12 @@ class SolrRequestHandlerController extends AbstractSolrEntityController { * Enables a Solr Entity on this server. * * @param \Drupal\search_api\ServerInterface $search_api_server + * Search API server. * @param \Drupal\search_api_solr\SolrConfigInterface $solr_request_handler + * Solr request handler. * - * @return RedirectResponse + * @return \Symfony\Component\HttpFoundation\RedirectResponse + * Redirect response. * * @throws \Drupal\Core\Entity\EntityStorageException */ diff --git a/src/Controller/SolrRequestHandlerListBuilder.php b/src/Controller/SolrRequestHandlerListBuilder.php index f0550e91..c200f153 100644 --- a/src/Controller/SolrRequestHandlerListBuilder.php +++ b/src/Controller/SolrRequestHandlerListBuilder.php @@ -8,6 +8,8 @@ namespace Drupal\search_api_solr\Controller; class SolrRequestHandlerListBuilder extends AbstractSolrEntityListBuilder { /** + * Request handler label. + * * @var string */ protected $label = 'Solr Request Handler'; @@ -16,6 +18,8 @@ class SolrRequestHandlerListBuilder extends AbstractSolrEntityListBuilder { * Returns a list of all disabled request handlers for current server. * * @return array + * List of all disqbled request handlers for current server. + * * @throws \Drupal\search_api\SearchApiException */ protected function getDisabledEntities(): array { diff --git a/src/Plugin/DataType/Deriver/SolrDocumentDeriver.php b/src/Plugin/DataType/Deriver/SolrDocumentDeriver.php index b9b329d2..bbbf820e 100644 --- a/src/Plugin/DataType/Deriver/SolrDocumentDeriver.php +++ b/src/Plugin/DataType/Deriver/SolrDocumentDeriver.php @@ -49,9 +49,9 @@ class SolrDocumentDeriver extends DeriverBase implements ContainerDeriverInterfa * SolrDocumentDeriver constructor. * * @param string $base_plugin_id - * Base plugin ID. + * Base plugin ID. * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager - * Entity type manager. + * Entity type manager. */ public function __construct($base_plugin_id, EntityTypeManagerInterface $entity_type_manager) { $this->basePluginId = $base_plugin_id; diff --git a/src/Plugin/DataType/SolrDocument.php b/src/Plugin/DataType/SolrDocument.php index ca24261d..5d74e6b2 100644 --- a/src/Plugin/DataType/SolrDocument.php +++ b/src/Plugin/DataType/SolrDocument.php @@ -25,8 +25,19 @@ use Solarium\Core\Query\DocumentInterface; */ class SolrDocument extends TypedData implements \IteratorAggregate, ComplexDataInterface { - protected $solr_field = 'solr_field'; - protected $solr_document = 'solr_document'; + /** + * Field name. + * + * @var string + */ + protected $solrField = 'solr_field'; + + /** + * Document name. + * + * @var string + */ + protected $solrDocument = 'solr_document'; /** * The wrapped Search API Item. @@ -78,8 +89,8 @@ class SolrDocument extends TypedData implements \IteratorAggregate, ComplexDataI // First, verify that this field actually exists in the Solr server. If we // can't get a definition for it, it doesn't exist. /** @var \Drupal\search_api_solr\Plugin\DataType\SolrField $plugin */ - $plugin = \Drupal::typedDataManager()->getDefinition($this->solr_field)['class']; - $field_manager = \Drupal::getContainer()->get($this->solr_field . '.manager'); + $plugin = \Drupal::typedDataManager()->getDefinition($this->solrField)['class']; + $field_manager = \Drupal::getContainer()->get($this->solrField . '.manager'); $fields = $field_manager->getFieldDefinitions($this->item->getIndex()); if (empty($fields[$property_name])) { throw new \InvalidArgumentException("The Solr field $property_name could not be found on the server."); @@ -92,7 +103,7 @@ class SolrDocument extends TypedData implements \IteratorAggregate, ComplexDataI $found = FALSE; foreach ($this->item->getFields(FALSE) as $field) { if ( - $field->getDatasourceId() === $this->solr_document && + $field->getDatasourceId() === $this->solrDocument && $field->getPropertyPath() === $property_name ) { $property->setValue($field->getValues()); diff --git a/src/Plugin/DataType/SolrField.php b/src/Plugin/DataType/SolrField.php index 0d397b63..0d86388e 100644 --- a/src/Plugin/DataType/SolrField.php +++ b/src/Plugin/DataType/SolrField.php @@ -21,7 +21,12 @@ use Drupal\search_api\Item\FieldInterface; */ class SolrField extends TypedData implements \IteratorAggregate { - protected static $solr_field = 'solr_field'; + /** + * Field name. + * + * @var string + */ + protected static $solrField = 'solr_field'; /** * The field value(s). @@ -45,7 +50,7 @@ class SolrField extends TypedData implements \IteratorAggregate { public static function createFromField(FieldInterface $field, $name, TypedDataInterface $parent) { // Get the Solr field definition from the SolrFieldManager. /** @var \Drupal\search_api_solr\SolrFieldManagerInterface $field_manager */ - $field_manager = \Drupal::getContainer()->get(static::$solr_field . 'solr_field.manager'); + $field_manager = \Drupal::getContainer()->get(static::$solrField . 'solr_field.manager'); $field_id = $field->getPropertyPath(); $definition = $field_manager->getFieldDefinitions($field->getIndex())[$field_id]; $instance = new static($definition, $name, $parent); diff --git a/src/Plugin/DataType/SolrMultisiteDocument.php b/src/Plugin/DataType/SolrMultisiteDocument.php index e9dd41e7..5d794297 100644 --- a/src/Plugin/DataType/SolrMultisiteDocument.php +++ b/src/Plugin/DataType/SolrMultisiteDocument.php @@ -17,7 +17,18 @@ namespace Drupal\search_api_solr\Plugin\DataType; */ class SolrMultisiteDocument extends SolrDocument { - protected $solr_field = 'solr_multisite_field'; - protected $solr_document = 'solr_multisite_document'; + /** + * Field name. + * + * @var string + */ + protected $solrField = 'solr_multisite_field'; + + /** + * Document name. + * + * @var string + */ + protected $solrDocument = 'solr_multisite_document'; } diff --git a/src/Plugin/DataType/SolrMultisiteField.php b/src/Plugin/DataType/SolrMultisiteField.php index 37fe26a3..579048c8 100644 --- a/src/Plugin/DataType/SolrMultisiteField.php +++ b/src/Plugin/DataType/SolrMultisiteField.php @@ -17,6 +17,12 @@ namespace Drupal\search_api_solr\Plugin\DataType; */ class SolrMultisiteField extends SolrField { - protected static $solr_field = 'solr_multisite_field'; + + /** + * Field name. + * + * @var string + */ + protected static $solrField = 'solr_multisite_field'; } diff --git a/src/Plugin/SolrConnector/StandardSolrCloudConnector.php b/src/Plugin/SolrConnector/StandardSolrCloudConnector.php index dc7d2113..5e42c486 100644 --- a/src/Plugin/SolrConnector/StandardSolrCloudConnector.php +++ b/src/Plugin/SolrConnector/StandardSolrCloudConnector.php @@ -138,7 +138,8 @@ class StandardSolrCloudConnector extends StandardSolrConnector implements SolrCl if ($checkpoints_collection) { try { return $this->getEndpoint($checkpoints_collection); - } catch (OutOfBoundsException $e) { + } + catch (OutOfBoundsException $e) { $additional_config['core'] = $checkpoints_collection; return $this->createEndpoint($checkpoints_collection, $additional_config); } @@ -274,7 +275,8 @@ class StandardSolrCloudConnector extends StandardSolrConnector implements SolrCl /** * Reloads collection. * - * @param string $collection + * @param string|null $collection + * Collection. * * @return bool * TRUE if successful, FALSE otherwise. @@ -324,4 +326,5 @@ class StandardSolrCloudConnector extends StandardSolrConnector implements SolrCl $files['solrconfig_extra.xml'] .= '' . "\n"; } } + } diff --git a/src/Plugin/search_api/parse_mode/SloppyPhrase.php b/src/Plugin/search_api/parse_mode/SloppyPhrase.php index 090eaccc..0eafcb9f 100644 --- a/src/Plugin/search_api/parse_mode/SloppyPhrase.php +++ b/src/Plugin/search_api/parse_mode/SloppyPhrase.php @@ -5,7 +5,9 @@ namespace Drupal\search_api_solr\Plugin\search_api\parse_mode; use Drupal\search_api\Plugin\search_api\parse_mode\Phrase; /** - * Represents a parse mode that parses the sentence into a sloppy search for the sentence. + * Represents a parse mode. + * + * A parse mode that parses the sentence into a sloppy search for the sentence. * * @SearchApiParseMode( * id = "sloppy_phrase", diff --git a/src/Plugin/search_api_autocomplete/suggester/Terms.php b/src/Plugin/search_api_autocomplete/suggester/Terms.php index 293b5ea0..8d64a301 100644 --- a/src/Plugin/search_api_autocomplete/suggester/Terms.php +++ b/src/Plugin/search_api_autocomplete/suggester/Terms.php @@ -21,7 +21,6 @@ class Terms extends Server { /** * {@inheritdoc} * - * * @throws \Drupal\search_api\SearchApiException * @throws \Drupal\search_api_autocomplete\SearchApiAutocompleteException */ diff --git a/src/SearchApiSolrConflictingEntitiesException.php b/src/SearchApiSolrConflictingEntitiesException.php index 33ea70fa..2f5aa7b2 100644 --- a/src/SearchApiSolrConflictingEntitiesException.php +++ b/src/SearchApiSolrConflictingEntitiesException.php @@ -10,22 +10,30 @@ use Drupal\Component\Render\FormattableMarkup; class SearchApiSolrConflictingEntitiesException extends SearchApiSolrException { /** + * Array with the conflicting entities. + * * @var \Drupal\search_api_solr\SolrConfigInterface[] */ - protected $conflicting_entities = []; + protected $conflictingEntities = []; /** + * Get the conflicting entities. + * * @return \Drupal\search_api_solr\SolrConfigInterface[] + * Array with the conflicting entities. */ public function getConflictingEntities(): array { - return $this->conflicting_entities; + return $this->conflictingEntities; } /** - * @param \Drupal\search_api_solr\SolrConfigInterface[] $conflicting_entities + * Set the conflicting entities. + * + * @param \Drupal\search_api_solr\SolrConfigInterface[] $conflictingEntities + * Array with the conflicting entities. */ - public function setConflictingEntities(array $conflicting_entities): void { - $this->conflicting_entities = $conflicting_entities; + public function setConflictingEntities(array $conflictingEntities): void { + $this->conflictingEntities = $conflictingEntities; } /** diff --git a/src/Solarium/Autocomplete/RequestBuilder.php b/src/Solarium/Autocomplete/RequestBuilder.php index 8ea972c4..33082b80 100644 --- a/src/Solarium/Autocomplete/RequestBuilder.php +++ b/src/Solarium/Autocomplete/RequestBuilder.php @@ -14,7 +14,7 @@ class RequestBuilder extends AbstractRequestBuilder { /** * Build request for an autocomplete query. * - * @param AbstractQuery $query + * @param \Solarium\Core\Query\AbstractQuery $query * The Solarium query. * * @return \Solarium\Core\Client\Request diff --git a/src/Solarium/Result/StreamDocument.php b/src/Solarium/Result/StreamDocument.php index 5c6a32b3..72f515bb 100644 --- a/src/Solarium/Result/StreamDocument.php +++ b/src/Solarium/Result/StreamDocument.php @@ -29,6 +29,7 @@ class StreamDocument extends AbstractDocument { * The field value. * * @return self + * Return a stream document. */ public function __set($name, $value): DocumentInterface { $this->fields[$name] = $value; diff --git a/src/SolrCloudConnectorInterface.php b/src/SolrCloudConnectorInterface.php index 038403c6..8b9b5de1 100644 --- a/src/SolrCloudConnectorInterface.php +++ b/src/SolrCloudConnectorInterface.php @@ -23,6 +23,7 @@ interface SolrCloudConnectorInterface extends SolrConnectorInterface { * Temporarily set a different collection name for the connection. * * @param \Solarium\Core\Client\Endpoint|null $endpoint + * Solr endpoint. */ public function setCollectionNameFromEndpoint(Endpoint $endpoint); @@ -30,6 +31,7 @@ interface SolrCloudConnectorInterface extends SolrConnectorInterface { * Returns the Solr collection name used to store topic checkpoints. * * @return string + * Solr collection name. */ public function getCheckpointsCollectionName(); @@ -37,6 +39,7 @@ interface SolrCloudConnectorInterface extends SolrConnectorInterface { * Returns the Solr collection endpoint used to store topic checkpoints. * * @return \Solarium\Core\Client\Endpoint|null + * Solr endpoint. */ public function getCheckpointsCollectionEndpoint(): ?Endpoint; @@ -44,13 +47,15 @@ interface SolrCloudConnectorInterface extends SolrConnectorInterface { * Deletes all checkpoints for given index/site. * * @param string $index_id + * Id of the index. * @param string $site_hash + * The site hash. * * @throws \Drupal\search_api_solr\SearchApiSolrException */ public function deleteCheckpoints(string $index_id, string $site_hash); - /** + /** * Returns a link to the Solr collection, if the necessary options are set. * * @return \Drupal\Core\Link diff --git a/src/SolrConnector/SolrConnectorPluginBase.php b/src/SolrConnector/SolrConnectorPluginBase.php index 7b015b38..91f6ee10 100644 --- a/src/SolrConnector/SolrConnectorPluginBase.php +++ b/src/SolrConnector/SolrConnectorPluginBase.php @@ -19,6 +19,7 @@ use Solarium\Exception\HttpException; use Solarium\QueryType\Extract\Result as ExtractResult; use Solarium\QueryType\Update\Query\Query as UpdateQuery; use Solarium\QueryType\Select\Query\Query; +use Drupal\search_api_solr\Solarium\Autocomplete\Query as AutocompleteQuery; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -714,7 +715,7 @@ abstract class SolrConnectorPluginBase extends ConfigurablePluginBase implements */ public function getAutocompleteQuery() { $this->connect(); - $this->solr->registerQueryType('autocomplete', \Drupal\search_api_solr\Solarium\Autocomplete\Query::class); + $this->solr->registerQueryType('autocomplete', AutocompleteQuery::class); return $this->solr->createQuery('autocomplete'); } @@ -865,7 +866,7 @@ abstract class SolrConnectorPluginBase extends ConfigurablePluginBase implements * * @param \Solarium\Exception\HttpException $e * The HttpException object. - * @param \Solarium\Core\Client\Endpoint $endpoint + * @param \Solarium\Core\Client\Endpoint|null $endpoint * The Solarium endpoint. * * @throws \Drupal\search_api_solr\SearchApiSolrException diff --git a/src/SolrConnectorInterface.php b/src/SolrConnectorInterface.php index e0cb26d2..32fce5cb 100644 --- a/src/SolrConnectorInterface.php +++ b/src/SolrConnectorInterface.php @@ -7,7 +7,6 @@ use Solarium\Core\Client\Endpoint; use Solarium\Core\Client\Request; use Solarium\Core\Client\Response; use Solarium\Core\Query\QueryInterface; -use Solarium\Exception\OutOfBoundsException; use Solarium\QueryType\Extract\Result as ExtractResult; use Solarium\QueryType\Update\Query\Query as UpdateQuery; use Solarium\QueryType\Select\Query\Query; @@ -433,7 +432,7 @@ interface SolrConnectorInterface extends ConfigurableInterface { * @return \Solarium\Core\Client\Endpoint * The Solarium endpoint object. * - * @throws OutOfBoundsException + * @throws \Solarium\Exception\OutOfBoundsException */ public function getEndpoint($key = 'search_api_solr'); diff --git a/src/SolrDocumentFactory.php b/src/SolrDocumentFactory.php index b2ef3fac..4a754a95 100644 --- a/src/SolrDocumentFactory.php +++ b/src/SolrDocumentFactory.php @@ -10,7 +10,12 @@ use Drupal\search_api\Item\ItemInterface; */ class SolrDocumentFactory implements SolrDocumentFactoryInterface { - protected static $solr_document = 'solr_document'; + /** + * Document name. + * + * @var string + */ + protected static $solrDocument = 'solr_document'; /** * A typed data manager. @@ -35,7 +40,7 @@ class SolrDocumentFactory implements SolrDocumentFactoryInterface { * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException */ public function create(ItemInterface $item) { - $plugin = $this->typedDataManager->getDefinition(static::$solr_document)['class']; + $plugin = $this->typedDataManager->getDefinition(static::$solrDocument)['class']; return $plugin::createFromItem($item); } diff --git a/src/SolrFieldTypeInterface.php b/src/SolrFieldTypeInterface.php index c885dd7b..7dae58d3 100644 --- a/src/SolrFieldTypeInterface.php +++ b/src/SolrFieldTypeInterface.php @@ -54,6 +54,7 @@ interface SolrFieldTypeInterface extends SolrConfigInterface { * The Solr Field Type definition as nested associative array. * * @return self + * Field type. */ public function setFieldType(array $field_type); @@ -81,6 +82,7 @@ interface SolrFieldTypeInterface extends SolrConfigInterface { * The Solr Field Type definition as JSON. * * @return self + * Field type as json. */ public function setFieldTypeAsJson($field_type); @@ -100,6 +102,7 @@ interface SolrFieldTypeInterface extends SolrConfigInterface { * The Solr SpellcheckField Type definition as nested associative array. * * @return self + * Spellcheck field type. */ public function setSpellcheckFieldType(array $spellcheck_field_type); @@ -128,6 +131,7 @@ interface SolrFieldTypeInterface extends SolrConfigInterface { * doesn't exist. * * @return self + * Spellcheck field type as json. */ public function setSpellcheckFieldTypeAsJson($spellcheck_field_type); @@ -162,6 +166,7 @@ interface SolrFieldTypeInterface extends SolrConfigInterface { * The Solr Collated Type definition as nested associative array. * * @return self + * Collated field type */ public function setCollatedFieldType(array $collated_field_type); @@ -190,6 +195,7 @@ interface SolrFieldTypeInterface extends SolrConfigInterface { * doesn't exist. * * @return self + * Collated field type as json. */ public function setCollatedFieldTypeAsJson($collated_field_type); @@ -211,7 +217,7 @@ interface SolrFieldTypeInterface extends SolrConfigInterface { /** * Gets the Solr Unstemmed Field Type definition as nested associative array. * - * @return array|NULL + * @return array|null * The Solr Unstemmed Field Type definition as nested associative array or * NULL if it doesn't exist. */ @@ -224,6 +230,7 @@ interface SolrFieldTypeInterface extends SolrConfigInterface { * The Solr Unstemmed Field Type definition as nested associative array. * * @return self + * Unstemmed field type. */ public function setUnstemmedFieldType(array $unstemmed_field_type); @@ -252,6 +259,7 @@ interface SolrFieldTypeInterface extends SolrConfigInterface { * doesn't exist. * * @return self + * Untemmed field type as json. */ public function setUnstemmedFieldTypeAsJson($unstemmed_field_type); @@ -265,8 +273,8 @@ interface SolrFieldTypeInterface extends SolrConfigInterface { * Solr Field Type. * * @return string - * The Solr Unstemmed Field Type definition as XML, might be empty if it - * doesn't exist. + * The Solr Unstemmed Field Type definition as XML, might be empty if it + * doesn't exist. */ public function getUnstemmedFieldTypeAsXml($add_comment = TRUE); @@ -321,6 +329,7 @@ interface SolrFieldTypeInterface extends SolrConfigInterface { * as values. * * @return self + * Text File. */ public function setTextFiles(array $text_files); diff --git a/src/SolrMultisiteDocumentFactory.php b/src/SolrMultisiteDocumentFactory.php index 886051ab..8ad5a402 100644 --- a/src/SolrMultisiteDocumentFactory.php +++ b/src/SolrMultisiteDocumentFactory.php @@ -7,6 +7,6 @@ namespace Drupal\search_api_solr; */ class SolrMultisiteDocumentFactory extends SolrDocumentFactory { - protected static $solr_document = 'solr_multisite_document'; + protected static $solrDocument = 'solr_multisite_document'; } diff --git a/src/Utility/CommandHelper.php b/src/Utility/SolrCommandHelper.php similarity index 97% rename from src/Utility/CommandHelper.php rename to src/Utility/SolrCommandHelper.php index 09341c01..2eba51f4 100644 --- a/src/Utility/CommandHelper.php +++ b/src/Utility/SolrCommandHelper.php @@ -4,11 +4,12 @@ namespace Drupal\search_api_solr\Utility; use Drupal\search_api_solr\Controller\SolrConfigSetController; use ZipStream\Option\Archive; +use Drupal\search_api\Utility\CommandHelper; /** * Provides functionality to be used by CLI tools. */ -class CommandHelper extends \Drupal\search_api\Utility\CommandHelper { +class SolrCommandHelper extends CommandHelper { /** * Re-install all Solr Field Types from their yml files. diff --git a/src/Utility/StreamingExpressionBuilder.php b/src/Utility/StreamingExpressionBuilder.php index 09888831..46f69d85 100644 --- a/src/Utility/StreamingExpressionBuilder.php +++ b/src/Utility/StreamingExpressionBuilder.php @@ -28,26 +28,26 @@ class StreamingExpressionBuilder extends ExpressionBuilder { * * @var string */ - protected $checkpoints_collection; + protected $checkpointsCollection; /** * @var string */ - protected $index_filter_query; + protected $indexFilterQuery; /** * The targeted Index ID. * * @var string */ - protected $targeted_index_id; + protected $targetedIndexId; /** * The targeted site hash. * * @var string */ - protected $targeted_site_hash; + protected $targetedSiteHash; /** * The Search API index entity. @@ -61,60 +61,63 @@ class StreamingExpressionBuilder extends ExpressionBuilder { * * @var string */ - protected $server_id; + protected $serverId; /** * The formatted request time. * * @var string */ - protected $request_time; + protected $requestTime; /** * The array of all mapped fields including graph fields. * * @var string[][] */ - protected $all_fields_including_graph_fields_mapped; + protected $allFieldsIncludingGraphFieldsMapped; /** * The array of all mapped fields. * * @var string[][] */ - protected $all_fields_mapped; + protected $allFieldsMapped; /** * The array of all mapped fields that have docValues. * * @var string[][] */ - protected $all_doc_value_fields_mapped; + protected $allDocValueFieldsMapped; /** * The array of all mapped sorting fields. * * @var string[][] */ - protected $sort_fields_mapped; + protected $sortFieldsMapped; /** * The Solarium query helper. * * @var \Solarium\Core\Query\Helper */ - protected $query_helper; + protected $queryHelper; /** - * The _search_all() and _topic_all() streaming expressions need a row limit - * is equal to or higher then the real number of rows. + * The _search_all() and _topic_all() streaming expressions need a row limit. + * + * The row limit is equal to or higher then the real number of rows. * * @var int */ - protected $search_all_rows; + protected $searchAllRows; /** - * @var SolrBackendInterface + * The Solr backend. + * + * @var \Drupal\search_api_solr\SolrBackendInterface */ protected $backend; @@ -129,7 +132,7 @@ class StreamingExpressionBuilder extends ExpressionBuilder { */ public function __construct(IndexInterface $index) { $server = $index->getServerInstance(); - $this->server_id = $server->id(); + $this->serverId = $server->id(); $this->backend = $server->getBackend(); $connector = $this->backend->getSolrConnector(); $index_settings = Utility::getIndexSolrSettings($index); @@ -140,20 +143,20 @@ class StreamingExpressionBuilder extends ExpressionBuilder { $language_ids = array_merge(array_keys(\Drupal::languageManager()->getLanguages()), [LanguageInterface::LANGCODE_NOT_SPECIFIED]); $this->collection = $index_settings['advanced']['collection'] ?: $connector->getCollectionName(); - $this->checkpoints_collection = $connector->getCheckpointsCollectionName(); - $this->index_filter_query = $this->backend->getIndexFilterQueryString($index); - $this->targeted_index_id = $this->backend->getTargetedIndexId($index); - $this->targeted_site_hash = $this->backend->getTargetedSiteHash($index); + $this->checkpointsCollection = $connector->getCheckpointsCollectionName(); + $this->indexFilterQuery = $this->backend->getIndexFilterQueryString($index); + $this->targetedIndexId = $this->backend->getTargetedIndexId($index); + $this->targetedSiteHash = $this->backend->getTargetedSiteHash($index); $this->index = $index; - $this->request_time = $this->backend->formatDate(\Drupal::time()->getRequestTime()); - $this->all_fields_mapped = []; + $this->requestTime = $this->backend->formatDate(\Drupal::time()->getRequestTime()); + $this->allFieldsMapped = []; foreach ($this->backend->getSolrFieldNamesKeyedByLanguage($language_ids, $index) as $search_api_field => $solr_field) { foreach ($solr_field as $language_id => $solr_field_name) { - $this->all_fields_mapped[$language_id][$search_api_field] = $solr_field_name; + $this->allFieldsMapped[$language_id][$search_api_field] = $solr_field_name; } } foreach ($language_ids as $language_id) { - $this->all_fields_mapped[$language_id] += [ + $this->allFieldsMapped[$language_id] += [ // Search API Solr Search specific fields. 'id' => Utility::hasIndexJustSolrDocumentDatasource($index) ? $index->get('datasource_settings')['solr_document']['id_field'] : 'id', 'index_id' => 'index_id', @@ -165,7 +168,7 @@ class StreamingExpressionBuilder extends ExpressionBuilder { 'spell' => 'spell', ]; - $this->all_fields_including_graph_fields_mapped[$language_id] = $this->all_fields_mapped[$language_id] + [ + $this->allFieldsIncludingGraphFieldsMapped[$language_id] = $this->allFieldsMapped[$language_id] + [ // Graph traversal reserved names. We can't get a conflict here since // all dynamic fields are prefixed. 'node' => 'node', @@ -175,31 +178,32 @@ class StreamingExpressionBuilder extends ExpressionBuilder { 'ancestors' => 'ancestors', ]; - $this->sort_fields_mapped[$language_id] = []; + $this->sortFieldsMapped[$language_id] = []; if (!Utility::hasIndexJustSolrDocumentDatasource($index)) { - foreach ($this->all_fields_mapped[$language_id] as $search_api_field => $solr_field) { + foreach ($this->allFieldsMapped[$language_id] as $search_api_field => $solr_field) { if (strpos($solr_field, 't') === 0 || strpos($solr_field, 's') === 0) { - $this->sort_fields_mapped[$language_id]['sort_' . $search_api_field] = Utility::encodeSolrName('sort' . SolrBackendInterface::SEARCH_API_SOLR_LANGUAGE_SEPARATOR . $language_id . '_' . $search_api_field); + $this->sortFieldsMapped[$language_id]['sort_' . $search_api_field] = Utility::encodeSolrName('sort' . SolrBackendInterface::SEARCH_API_SOLR_LANGUAGE_SEPARATOR . $language_id . '_' . $search_api_field); } elseif (preg_match('/^([a-z]+)m(_.*)/', $solr_field, $matches) && strpos($solr_field, 'random_') !== 0) { - $this->sort_fields_mapped[$language_id]['sort' . Utility::decodeSolrName($matches[2])] = $matches[1] . 's' . $matches[2]; + $this->sortFieldsMapped[$language_id]['sort' . Utility::decodeSolrName($matches[2])] = $matches[1] . 's' . $matches[2]; } if ( - strpos($solr_field, 's') === 0 || // Covers sort_*, too. + // Covers sort_*, too. + strpos($solr_field, 's') === 0 || strpos($solr_field, 'i') === 0 || strpos($solr_field, 'f') === 0 || strpos($solr_field, 'p') === 0 || strpos($solr_field, 'b') === 0 || strpos($solr_field, 'h') === 0 ) { - $this->all_doc_value_fields_mapped[$language_id][$search_api_field] = $solr_field; + $this->allDocValueFieldsMapped[$language_id][$search_api_field] = $solr_field; } } } } - $this->query_helper = $connector->getQueryHelper(); + $this->queryHelper = $connector->getQueryHelper(); } /** @@ -219,7 +223,7 @@ class StreamingExpressionBuilder extends ExpressionBuilder { * The checkpoints collection name. */ public function _checkpoints_collection() { - return $this->checkpoints_collection; + return $this->checkpointsCollection; } /** @@ -236,14 +240,14 @@ class StreamingExpressionBuilder extends ExpressionBuilder { * @throws \InvalidArgumentException */ public function _field(string $search_api_field_name, string $language_id = LanguageInterface::LANGCODE_NOT_SPECIFIED) { - if (!isset($this->all_fields_including_graph_fields_mapped[$language_id][$search_api_field_name])) { - if (isset($this->sort_fields_mapped[$language_id][$search_api_field_name])) { - return $this->sort_fields_mapped[$language_id][$search_api_field_name]; + if (!isset($this->allFieldsIncludingGraphFieldsMapped[$language_id][$search_api_field_name])) { + if (isset($this->sortFieldsMapped[$language_id][$search_api_field_name])) { + return $this->sortFieldsMapped[$language_id][$search_api_field_name]; } - throw new \InvalidArgumentException(sprintf('Field %s does not exist in index %s.', $search_api_field_name, $this->targeted_index_id)); + throw new \InvalidArgumentException(sprintf('Field %s does not exist in index %s.', $search_api_field_name, $this->targetedIndexId)); } - return $this->all_fields_including_graph_fields_mapped[$language_id][$search_api_field_name]; + return $this->allFieldsIncludingGraphFieldsMapped[$language_id][$search_api_field_name]; } /** @@ -287,7 +291,7 @@ class StreamingExpressionBuilder extends ExpressionBuilder { public function _all_fields_list(string $delimiter = ',', bool $include_sorts = TRUE, array $blacklist = [], string $language_id = LanguageInterface::LANGCODE_NOT_SPECIFIED) { $blacklist = array_merge($blacklist, ['search_api_relevance', 'search_api_random']); return implode($delimiter, array_diff_key( - ($include_sorts ? array_merge($this->all_fields_mapped[$language_id], $this->sort_fields_mapped[$language_id]) : $this->all_fields_mapped[$language_id]), + ($include_sorts ? array_merge($this->allFieldsMapped[$language_id], $this->sortFieldsMapped[$language_id]) : $this->allFieldsMapped[$language_id]), array_flip($blacklist)) ); } @@ -311,7 +315,7 @@ class StreamingExpressionBuilder extends ExpressionBuilder { $blacklist = array_merge($blacklist, ['search_api_relevance', 'search_api_random']); return implode($delimiter, array_diff_key( // All sort fields have docValues. - ($include_sorts ? array_merge($this->all_doc_value_fields_mapped[$language_id], $this->sort_fields_mapped[$language_id]) : $this->all_doc_value_fields_mapped[$language_id]), + ($include_sorts ? array_merge($this->allDocValueFieldsMapped[$language_id], $this->sortFieldsMapped[$language_id]) : $this->allDocValueFieldsMapped[$language_id]), array_flip($blacklist)) ); } @@ -344,8 +348,8 @@ class StreamingExpressionBuilder extends ExpressionBuilder { } } $escaped_string = $single_term ? - $this->query_helper->escapeTerm($value) : - $this->query_helper->escapePhrase($value); + $this->queryHelper->escapeTerm($value) : + $this->queryHelper->escapePhrase($value); // If the escaped strings are to be used inside a streaming expression // double quotes need to be escaped once more. // (e.g. q="field:\"word1 word2\""). @@ -643,7 +647,7 @@ class StreamingExpressionBuilder extends ExpressionBuilder { * The filter query ready to use for the 'fq' parameter. */ public function _index_filter_query() { - return $this->index_filter_query; + return $this->indexFilterQuery; } /** @@ -653,7 +657,7 @@ class StreamingExpressionBuilder extends ExpressionBuilder { * The index ID. */ public function _index_id() { - return $this->targeted_index_id; + return $this->targetedIndexId; } /** @@ -665,7 +669,7 @@ class StreamingExpressionBuilder extends ExpressionBuilder { * The site hash. */ public function _site_hash() { - return $this->targeted_site_hash; + return $this->targetedSiteHash; } /** @@ -675,7 +679,7 @@ class StreamingExpressionBuilder extends ExpressionBuilder { * The formatted date. */ public function _request_time() { - return $this->request_time; + return $this->requestTime; } /** @@ -685,14 +689,14 @@ class StreamingExpressionBuilder extends ExpressionBuilder { * The timestamp expression. */ public function _timestamp_value() { - return 'val(' . $this->request_time . ') as timestamp'; + return 'val(' . $this->requestTime . ') as timestamp'; } /** * Eases topic() expressions if there's no specific checkpoint collection. * * @return string - * A chainable streaming expression as string. + * A chainable streaming expression as string. */ public function _topic() { return $this->topic( @@ -707,7 +711,7 @@ class StreamingExpressionBuilder extends ExpressionBuilder { * Eases topic() expressions if there's no specific checkpoint collection. * * @return string - * A chainable streaming expression as string. + * A chainable streaming expression as string. */ public function _topic_all() { return $this->topic( @@ -725,12 +729,13 @@ class StreamingExpressionBuilder extends ExpressionBuilder { * The checkpoint name gets suffixed by targeted index and site hash to avoid * collisions. * - * @param $checkpoint + * @param string $checkpoint * * @return string + * Formatted checkpoint parameter. */ public function _checkpoint($checkpoint) { - return 'id="' . Utility::formatCheckpointId($checkpoint, $this->targeted_index_id, $this->targeted_site_hash) . '"'; + return 'id="' . Utility::formatCheckpointId($checkpoint, $this->targetedIndexId, $this->targetedSiteHash) . '"'; } /** @@ -745,6 +750,7 @@ class StreamingExpressionBuilder extends ExpressionBuilder { * 1024 as fallback. * * @return int + * Integer of the row limit. * * @throws \Drupal\Component\Plugin\Exception\PluginException * @throws \Drupal\search_api\SearchApiException @@ -753,16 +759,17 @@ class StreamingExpressionBuilder extends ExpressionBuilder { * @see search_api_solr_cron() */ public function getSearchAllRows() { - if (!$this->search_all_rows) { + if (!$this->searchAllRows) { $rows = \Drupal::state()->get('search_api_solr.search_all_rows', []); - $this->search_all_rows = $rows[$this->server_id][$this->targeted_site_hash][$this->targeted_index_id] ?? FALSE; - if (FALSE === $this->search_all_rows) { + $this->searchAllRows = $rows[$this->serverId][$this->targetedSiteHash][$this->targetedIndexId] ?? FALSE; + if (FALSE === $this->searchAllRows) { $counts = $this->backend->getDocumentCounts(); - $this->search_all_rows = $rows[$this->server_id][$this->targeted_site_hash][$this->targeted_index_id] = - Utility::normalizeMaxRows($counts[$this->targeted_site_hash][$this->targeted_index_id] ?? ($counts['#total'] ?? 512)); + $this->searchAllRows = $rows[$this->serverId][$this->targetedSiteHash][$this->targetedIndexId] = + Utility::normalizeMaxRows($counts[$this->targetedSiteHash][$this->targetedIndexId] ?? ($counts['#total'] ?? 512)); \Drupal::state()->set('search_api_solr.search_all_rows', $rows); } } - return $this->search_all_rows; + return $this->searchAllRows; } + } diff --git a/src/Utility/StreamingExpressionQueryHelper.php b/src/Utility/StreamingExpressionQueryHelper.php index 26efa375..2359f3c1 100644 --- a/src/Utility/StreamingExpressionQueryHelper.php +++ b/src/Utility/StreamingExpressionQueryHelper.php @@ -31,8 +31,10 @@ class StreamingExpressionQueryHelper extends QueryHelper { * * @param \Drupal\search_api\Query\QueryInterface $query * The Search API query. - * @param string $streaming_expression + * @param \Drupal\search_api_solr\Utility\string $streaming_expression * The streaming expression to set for this query. + * @param \Drupal\search_api_solr\Utility\string $comment + * A comment of the streaming expression. */ public function setStreamingExpression(QueryInterface $query, string $streaming_expression, string $comment = '') { if ($comment) { diff --git a/src/Utility/Utility.php b/src/Utility/Utility.php index 15431d26..32dbd037 100644 --- a/src/Utility/Utility.php +++ b/src/Utility/Utility.php @@ -7,7 +7,6 @@ use Drupal\datetime\Plugin\Field\FieldType\DateTimeItemInterface; use Drupal\search_api\IndexInterface; use Drupal\search_api\Query\QueryInterface; use Drupal\search_api\ServerInterface; -use Drupal\search_api_solr\Entity\AbstractSolrEntity; use Drupal\search_api_solr\Entity\SolrCache; use Drupal\search_api_solr\Entity\SolrRequestDispatcher; use Drupal\search_api_solr\Entity\SolrRequestHandler; @@ -587,8 +586,10 @@ class Utility { * the available memory is 2147483629. So we use this a cut-off. * * @param int $rows + * The number of rows. * * @return int + * Normalized number of rows. */ public static function normalizeMaxRows(int $rows) { $i = 2; @@ -771,7 +772,6 @@ class Utility { $sloppiness = '~10000000'; // No break! Execute 'default', too. 'terms' will be skipped when $k // just contains one element. - case 'terms': if (count($k) > 1 && count($fields) > 0) { $key_parts = []; @@ -794,7 +794,6 @@ class Utility { $query_parts[] = '(' . implode(' ', $key_parts) . ')'; } // No break! Execute 'default', too. - default: if ($sloppiness) { foreach ($k as &$term_or_phrase) { @@ -974,8 +973,10 @@ class Utility { * 4. storage time zone (UTC) * * @param \Drupal\search_api\IndexInterface $index + * The Solr index. * * @return string + * The timezone. */ public static function getTimeZone(IndexInterface $index): string { $settings = self::getIndexSolrSettings($index); @@ -1021,6 +1022,7 @@ class Utility { * @param string $site_hash * * @return string + * The formatted checkpoint ID. */ public static function formatCheckpointId(string $checkpoint, string $index_id, string $site_hash): string { return $checkpoint . '-' . $index_id . '-' . $site_hash; @@ -1043,15 +1045,18 @@ class Utility { } /** + * Normalize a XML file. + * * Removes comments from an xml file and removes the 'name' attribute of the * root node. * * @param string $xml - * + * The XML file to normalize. * * @return array + * An array with the version number and the normalized XML. */ - public static function normalizeXML($xml): array { + public static function normalizeXml($xml): array { $document = new \DOMDocument(); if (@$document->loadXML($xml) === FALSE) { $document->loadXML("$xml");