You are here

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

Same name and namespace in other branches
  1. 8.3 src/Utility/Utility.php \Drupal\search_api_solr\Utility\Utility::getSiteHash()
  2. 8.2 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.

5 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::search in src/Plugin/search_api/backend/SearchApiSolrBackend.php
Options on $query prefixed by 'solr_param_' will be passed natively to Solr as query parameter without the prefix. For example you can set the "Minimum Should Match" parameter 'mm' to '75%' like this:

File

src/Utility/Utility.php, line 122

Class

Utility
Utility functions specific to solr.

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;
}