public function SearchApiSolrBackend::finalizeIndex in Search API Solr 8.2
Same name and namespace in other branches
- 8.3 src/Plugin/search_api/backend/SearchApiSolrBackend.php \Drupal\search_api_solr\Plugin\search_api\backend\SearchApiSolrBackend::finalizeIndex()
- 4.x src/Plugin/search_api/backend/SearchApiSolrBackend.php \Drupal\search_api_solr\Plugin\search_api\backend\SearchApiSolrBackend::finalizeIndex()
Parameters
\Drupal\search_api\IndexInterface $index:
Throws
\Drupal\search_api_solr\SearchApiSolrException
Overrides SolrBackendInterface::finalizeIndex
3 calls to SearchApiSolrBackend::finalizeIndex()
- SearchApiSolrBackend::executeGraphStreamingExpression in src/
Plugin/ search_api/ backend/ SearchApiSolrBackend.php - Executes a graph streaming expression.
- SearchApiSolrBackend::executeStreamingExpression in src/
Plugin/ search_api/ backend/ SearchApiSolrBackend.php - Executes a streaming expression.
- 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/
Plugin/ search_api/ backend/ SearchApiSolrBackend.php, line 926
Class
- SearchApiSolrBackend
- Apache Solr backend for search api.
Namespace
Drupal\search_api_solr\Plugin\search_api\backendCode
public function finalizeIndex(IndexInterface $index) {
// Avoid endless loops if finalization hooks trigger searches or streaming
// expressions themselves.
static $finalization_in_progress = [];
if (!isset($finalization_in_progress[$index
->id()]) && !$index
->isReadOnly()) {
$settings = $index
->getThirdPartySettings('search_api_solr') + search_api_solr_default_index_third_party_settings();
if (!empty($settings['finalize']) && \Drupal::state()
->get('search_api_solr.' . $index
->id() . '.last_update', 0) >= \Drupal::state()
->get('search_api_solr.' . $index
->id() . '.last_finalization', 0)) {
$lock = \Drupal::lock();
$lock_name = 'search_api_solr.' . $index
->id() . '.finalization_lock';
if ($lock
->acquire($lock_name)) {
$vars = [
'%index_id' => $index
->id(),
'%pid' => getmypid(),
];
$this
->getLogger()
->debug('PID %pid, Index %index_id: Finalization lock acquired.', $vars);
$finalization_in_progress[$index
->id()] = TRUE;
$connector = $this
->getSolrConnector();
$previous_timeout = $connector
->adjustTimeout($connector
->getFinalizeTimeout());
try {
if (!empty($settings['commit_before_finalize'])) {
$this
->ensureCommit($this
->getServer());
}
$this->moduleHandler
->invokeAll('search_api_solr_finalize_index', [
$index,
]);
if (!empty($settings['commit_after_finalize'])) {
$this
->ensureCommit($this
->getServer());
}
\Drupal::state()
->set('search_api_solr.' . $index
->id() . '.last_finalization', \Drupal::time()
->getRequestTime());
$lock
->release($lock_name);
$vars = [
'%index_id' => $index
->id(),
'%pid' => getmypid(),
];
$this
->getLogger()
->debug('PID %pid, Index %index_id: Finalization lock released.', $vars);
} catch (\Exception $e) {
unset($finalization_in_progress[$index
->id()]);
$lock
->release('search_api_solr.' . $index
->id() . '.finalization_lock');
$connector
->adjustTimeout($previous_timeout);
if ($e instanceof StreamException) {
throw new SearchApiSolrException($e
->getMessage() . "\n" . Expression::indent($e
->getExpression()), $e
->getCode(), $e);
}
throw new SearchApiSolrException($e
->getMessage(), $e
->getCode(), $e);
}
unset($finalization_in_progress[$index
->id()]);
$connector
->adjustTimeout($previous_timeout);
}
else {
if ($lock
->wait($lock_name)) {
// wait() returns TRUE if the lock isn't released within the given
// timeout (default 30s).
$vars = [
'%index_id' => $index
->id(),
'%pid' => getmypid(),
];
$this
->getLogger()
->debug('PID %pid, Index %index_id: Waited unsuccessfully for finalization lock.', $vars);
throw new SearchApiSolrException('The search index currently being rebuilt. Try again later.');
}
$this
->finalizeIndex($index);
}
}
}
}