You are here

protected function SearchApiSolrBackend::addIndexField in Search API Solr 8

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

Helper method for indexing.

Adds $value with field name $key to the document $doc. The format of $value is the same as specified in \Drupal\search_api\Backend\BackendSpecificInterface::indexItems().

1 call to SearchApiSolrBackend::addIndexField()
SearchApiSolrBackend::getDocuments in src/Plugin/search_api/backend/SearchApiSolrBackend.php
Retrieves Solr documents from search api index items.

File

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

Class

SearchApiSolrBackend
Apache Solr backend for search api.

Namespace

Drupal\search_api_solr\Plugin\search_api\backend

Code

protected function addIndexField(Document $doc, $key, array $values, $type) {

  // Don't index empty values (i.e., when field is missing).
  if (!isset($values)) {
    return;
  }

  // All fields.
  foreach ($values as $value) {
    switch ($type) {
      case 'boolean':
        $value = $value ? 'true' : 'false';
        break;
      case 'date':
        $value = $this
          ->formatDate($value);
        if ($value === FALSE) {
          return;
        }
        break;
      case 'integer':
        $value = (int) $value;
        break;
      case 'decimal':
        $value = (double) $value;
        break;
      case 'text':

        /** @var \Drupal\search_api\Plugin\search_api\data_type\value\TextValueInterface $value */

        /*
        $tokens = $value->getTokens();
        if (is_array($tokens)) {
          foreach ($tokens as $token) {
            // @todo handle token boosts
            // @see https://www.drupal.org/node/2746263
            #$doc->addField($boost_key, $tokenized_value['value'], $tokenized_value['score']);
            $token->getText();
            $token->getBoost();
          }
        }
        */
        $value = $value
          ->toText();
        break;
      case 'string':
      default:
    }
    $doc
      ->addField($key, $value);
  }
}