You are here

public function DoubleQuoteWorkaround::postprocessSearchResults in Search API Solr 8.2

Same name and namespace in other branches
  1. 8.3 src/Plugin/search_api/processor/DoubleQuoteWorkaround.php \Drupal\search_api_solr\Plugin\search_api\processor\DoubleQuoteWorkaround::postprocessSearchResults()
  2. 4.x src/Plugin/search_api/processor/DoubleQuoteWorkaround.php \Drupal\search_api_solr\Plugin\search_api\processor\DoubleQuoteWorkaround::postprocessSearchResults()

Postprocess search results before they are returned by the query.

If a processor is used for both pre- and post-processing a search query, the same object will be used for both calls (so preserving some data or state locally is possible).

Parameters

\Drupal\search_api\Query\ResultSetInterface $results: The search results.

Overrides ProcessorPluginBase::postprocessSearchResults

File

src/Plugin/search_api/processor/DoubleQuoteWorkaround.php, line 83

Class

DoubleQuoteWorkaround
Replaces double quotes in field values and query to work around a bug in Solr streaming expressions.

Namespace

Drupal\search_api_solr\Plugin\search_api\processor

Code

public function postprocessSearchResults(ResultSetInterface $results) {
  foreach ($results
    ->getResultItems() as $resultItem) {
    foreach ($resultItem
      ->getFields(FALSE) as $field) {
      $values = $field
        ->getValues();
      foreach ($values as $key => $value) {
        if (is_string($value)) {
          $values[$key] = $this
            ->decodeStreamingExpressionValue($value);
        }
        elseif ($value instanceof TextValueInterface) {
          $value
            ->setText($this
            ->decodeStreamingExpressionValue($value
            ->getText()));
        }
      }
      $field
        ->setValues($values);
    }
  }
}