You are here

public function SolrConnectorPluginBase::update in Search API Solr 8.2

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

Executes an update query and applies some tweaks.

Parameters

\Solarium\QueryType\Update\Query\Query $query:

\Solarium\Core\Client\Endpoint|null $endpoint:

Return value

\Solarium\Core\Query\Result\ResultInterface

Overrides SolrConnectorInterface::update

File

src/SolrConnector/SolrConnectorPluginBase.php, line 790

Class

SolrConnectorPluginBase
Defines a base class for Solr connector plugins.

Namespace

Drupal\search_api_solr\SolrConnector

Code

public function update(UpdateQuery $query, Endpoint $endpoint = NULL) {
  $this
    ->connect();
  if (!$endpoint) {
    $endpoint = $this->solr
      ->getEndpoint('core');
  }

  // The default timeout is set for search queries. The configured timeout
  // might differ and needs to be set now because solarium doesn't
  // distinguish between these types.
  $timeout = $endpoint
    ->getTimeout();
  $endpoint
    ->setTimeout($this->configuration['index_timeout']);
  if ($this->configuration['commit_within']) {

    // Do a commitWithin since that is automatically a softCommit since Solr 4
    // and a delayed hard commit with Solr 3.4+.
    // By default we wait 1 second after the request arrived for solr to parse
    // the commit. This allows us to return to Drupal and let Solr handle what
    // it needs to handle.
    // @see http://wiki.apache.org/solr/NearRealtimeSearch

    /** @var \Solarium\Plugin\CustomizeRequest\CustomizeRequest $request */
    $request = $this
      ->customizeRequest();
    $request
      ->createCustomization('id')
      ->setType('param')
      ->setName('commitWithin')
      ->setValue($this->configuration['commit_within']);
  }
  $result = $this
    ->execute($query, $endpoint);

  // Reset the timeout setting to the default value for search queries.
  $endpoint
    ->setTimeout($timeout);
  return $result;
}