You are here

public static function Utility::getSiteHash in Search API Solr 8.2

Same name and namespace in other branches
  1. 8.3 src/Utility/Utility.php \Drupal\search_api_solr\Utility\Utility::getSiteHash()
  2. 8 src/Utility/Utility.php \Drupal\search_api_solr\Utility\Utility::getSiteHash()
  3. 4.x src/Utility/Utility.php \Drupal\search_api_solr\Utility\Utility::getSiteHash()

Returns a unique hash for the current site.

This is used to identify Solr documents from different sites within a single Solr server.

Return value

string A unique site hash, containing only alphanumeric characters.

8 calls to Utility::getSiteHash()
SearchApiSolrBackend::createId in src/Plugin/search_api/backend/SearchApiSolrBackend.php
Creates an ID used as the unique identifier at the Solr server.
SearchApiSolrBackend::deleteAllIndexItems in src/Plugin/search_api/backend/SearchApiSolrBackend.php
Deletes all the items from the index.
SearchApiSolrBackend::extractResults in src/Plugin/search_api/backend/SearchApiSolrBackend.php
Extract results from a Solr response.
SearchApiSolrBackend::getDocuments in src/Plugin/search_api/backend/SearchApiSolrBackend.php
Retrieves Solr documents from search api index items.
SearchApiSolrBackend::getIndexFilterQueryString in src/Plugin/search_api/backend/SearchApiSolrBackend.php
Returns a ready to use query string to filter results by index and site.

... See full list

File

src/Utility/Utility.php, line 137

Class

Utility
Provides various helper functions for Solr backends.

Namespace

Drupal\search_api_solr\Utility

Code

public static function getSiteHash() {

  // Copied from apachesolr_site_hash().
  if (!($hash = \Drupal::config('search_api_solr.settings')
    ->get('site_hash'))) {
    global $base_url;
    $hash = substr(base_convert(sha1(uniqid($base_url, TRUE)), 16, 36), 0, 6);
    \Drupal::configFactory()
      ->getEditable('search_api_solr.settings')
      ->set('site_hash', $hash)
      ->save();
  }
  return $hash;
}