Information for: DEVELOPERS   PARTNERS   SUPPORT

Overriding Solr index connection switching

Occasionally, you must override the auto switching behavior in Acquia Search for specific reasons (which can include the following):

  • You are implementing a single search page returning results from several Drupal websites. For this approach, all websites must read and write to a single Solr index and use a module such as the Apache Solr Multisite Search module to power your search pages.
  • Your subscription level isn’t entitled to several Acquia Search Solr indexes, and you must write into your single, available index from several environments.
  • You must read/write access from a local- or non-Acquia-hosted website.

Important

Sharing a single Solr index across websites has risks. For more information, see Sharing Solr indexes in read/write mode.

To stop Acquia Search from enabling auto switching, use one of the following methods:

Using code overrides to set the Acquia Search Solr connection

Acquia Search subscribers can choose to manually configure the connections in the settings.php file by overriding variables. For non-hosted subscribers, setting these variables is the only available method to use multiple Acquia Search Solr indexes.

Code override procedure

Note for Site Factory subscribers

Site Factory subscribers must modify the following provided code examples to use $GLOBALS['gardens_site_settings']['env'] instead of $_ENV['AH_SITE_ENVIRONMENT'], as the value of $_ENV['AH_SITE_ENVIRONMENT'] changes during the code deployment process.

Select the code override to use based on your installed Drupal version and the module in use, from the following tabs:

Note

This requires acquia_connector-8.x-1.20 or higher.

To override the connection:

  • For Site Factory, place the following code inside a post-settings-php hook file.
  • For all other cases, you can put the following code in your settings.php file after the Acquia include statement.
// Override the ID of the Acquia Search Solr core to use.
// Replace ABCD-123456.env.mysite with the Solr core ID you wish to connect to

// For acquia_search-8.x-2.x
$config['acquia_search.settings']['default_search_core'] = 'ABCD-123456.env.mysite';

// For acquia_search-8.x-3.x
$config['acquia_search.settings']['override_search_core'] = 'ABCD-123456.env.mysite';
// connect to the ABCD-12345.dev.mysite Solr index
$conf['acquia_search_solr_search_index'] = "ABCD-12345.dev.mysite";

Disabling auto switching

Note for Site Factory subscribers

Site Factory subscribers must modify the following provided code examples to use $GLOBALS['gardens_site_settings']['env'] instead of $_ENV['AH_SITE_ENVIRONMENT'], as the value of $_ENV['AH_SITE_ENVIRONMENT'] changes during the code deployment process.

Code Override for Acquia Search with Solr 7

Setting acquia_search.settings.read_only to TRUE avoids auto switching, causing the production Solr index to enforce read/write mode as shown in the following code example:

$config['acquia_search.settings']['read_only'] = TRUE;