You are here

protected function SearchApiSolrMultilingualBackend::solrRestPost in Apache Solr Multilingual 8

Sends a REST POST request and return the result.

Parameters

string $path The path to append to the base URI:

string $command_json The JSON-encoded data.:

IndexInterface $index The index whose server the request should be sent to:

Return value

string The decoded response

See also

https://cwiki.apache.org/confluence/display/solr/Schema+API

2 calls to SearchApiSolrMultilingualBackend::solrRestPost()
SearchApiSolrMultilingualBackend::createSolrDynamicField in src/Plugin/search_api/backend/SearchApiSolrMultilingualBackend.php
SearchApiSolrMultilingualBackend::createSolrMultilingualFieldType in src/Plugin/search_api/backend/SearchApiSolrMultilingualBackend.php

File

src/Plugin/search_api/backend/SearchApiSolrMultilingualBackend.php, line 358
Contains \Drupal\as_search\Plugin\search_api\backend\ASSearchApiSolrBackend.

Class

SearchApiSolrMultilingualBackend
Plugin annotation @SearchApiBackend( id = "search_api_solr_multilingual", label = @Translation("Solr Multilingual"), description = @Translation("Index items using an Apache Solr Multilingual search server.") )

Namespace

Drupal\apachesolr_multilingual\Plugin\search_api\backend

Code

protected function solrRestPost($path, $command_json, IndexInterface $index) {
  $uri = $this->solr
    ->getEndpoint()
    ->getBaseUri() . $path;

  /** @var \GuzzleHttp\Client $client */
  $client = \Drupal::service('http_client');
  $result = $client
    ->post($uri, [
    'body' => $command_json,
    'headers' => [
      'Accept' => 'application/json',
      'Content-type' => 'application/json',
    ],
  ]);
  $output = Json::decode($result
    ->getBody());

  // \Drupal::logger('apachesolr_multilingual')->info(print_r($output, true));
  if (!empty($output['errors'])) {
    throw new SearchApiException("Error trying to send the following JSON to Solr (REST POST request to '{$uri}'): " . $command_json . "\nError message(s):" . print_r($output['errors'], TRUE));
  }
  return $output;
}