You are here

public static function Helpers::getSelectHandlerUrl in Search API Federated Solr 4.x

Same name and namespace in other branches
  1. 8.3 src/Utility/Helpers.php \Drupal\search_api_federated_solr\Utility\Helpers::getSelectHandlerUrl()
  2. 8.2 src/Utility/Helpers.php \Drupal\search_api_federated_solr\Utility\Helpers::getSelectHandlerUrl()

Determines URL for select handler of the selected index backend

Return value

string URL for the solr backend /select request handler

1 call to Helpers::getSelectHandlerUrl()
Helpers::getEndpointUrl in src/Utility/Helpers.php
Determines url to use for app search + autocomplete queries based on config:

File

src/Utility/Helpers.php, line 19

Class

Helpers
Contains helper methods for the Search API Federated Solr module.

Namespace

Drupal\search_api_federated_solr\Utility

Code

public static function getSelectHandlerUrl() {
  $server_url = '';

  // Get the id of the chosen index's server.
  $app_config = \Drupal::config('search_api_federated_solr.search_app.settings');
  $index_id = $app_config
    ->get('index.id');

  // Get index config.
  $index_config = \Drupal::config('search_api.index.' . $index_id);

  // Get the index's server name.
  $server_id = $index_config
    ->get('server');

  // Load the server.

  /** @var \Drupal\search_api\ServerInterface $server */
  $server = Server::load($server_id);
  try {

    /** @var \Drupal\search_api_solr\SolrBackendInterface $backend */
    $backend = $server
      ->getBackend();

    /** @var \Drupal\search_api_solr\SolrConnectorInterface $connector */
    $connector = $backend
      ->getSolrConnector();

    /** @var \Drupal\Url */
    $server_link = $connector
      ->getCoreLink();
    $server_url = $server_link
      ->getUrl()
      ->toUriString();

    // The core link includes /#/, which we cannot use.
    $server_url = str_replace('/#/', '/', $server_url);
    $server_url .= '/select';
  } catch (SearchApiException $e) {
    watchdog_exception('search_api_federated_solr', $e, '%type while getting backend + connector for @server: @message in %function (line %line of %file).', array(
      '@server' => $server
        ->label(),
    ));
  }
  return $server_url;
}