You are here

public function SearchApiSolrBackend::executeGraphStreamingExpression in Search API Solr 8.3

Same name and namespace in other branches
  1. 8.2 src/Plugin/search_api/backend/SearchApiSolrBackend.php \Drupal\search_api_solr\Plugin\search_api\backend\SearchApiSolrBackend::executeGraphStreamingExpression()
  2. 4.x src/Plugin/search_api/backend/SearchApiSolrBackend.php \Drupal\search_api_solr\Plugin\search_api\backend\SearchApiSolrBackend::executeGraphStreamingExpression()

Throws

\Drupal\Component\Plugin\Exception\PluginException

Overrides SolrBackendInterface::executeGraphStreamingExpression

File

src/Plugin/search_api/backend/SearchApiSolrBackend.php, line 1868

Class

SearchApiSolrBackend
Apache Solr backend for search api.

Namespace

Drupal\search_api_solr\Plugin\search_api\backend

Code

public function executeGraphStreamingExpression(QueryInterface $query) {
  $stream_expression = $query
    ->getOption('solr_streaming_expression', FALSE);
  if (!$stream_expression) {
    throw new SearchApiSolrException('Streaming expression missing.');
  }
  $connector = $this
    ->getSolrConnector();
  if (!$connector instanceof SolrCloudConnectorInterface) {
    throw new SearchApiSolrException('Streaming expression are only supported by a Solr Cloud connector.');
  }
  $index = $query
    ->getIndex();
  $this
    ->finalizeIndex($index);
  $graph = $connector
    ->getGraphQuery();
  $graph
    ->setExpression($stream_expression);
  $this
    ->applySearchWorkarounds($graph, $query);
  try {
    return $connector
      ->graph($graph, $this
      ->getCollectionEndpoint($index));
  } catch (\Exception $e) {
    throw new SearchApiSolrException('An error occurred while trying execute a streaming expression on Solr: ' . $e
      ->getMessage(), $e
      ->getCode(), $e);
  }
}