You are here

protected function SearchApiSolrBackend::getPropertyPathCardinality in Search API Solr 8.2

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::getPropertyPathCardinality()
  2. 8 src/Plugin/search_api/backend/SearchApiSolrBackend.php \Drupal\search_api_solr\Plugin\search_api\backend\SearchApiSolrBackend::getPropertyPathCardinality()
  3. 4.x src/Plugin/search_api/backend/SearchApiSolrBackend.php \Drupal\search_api_solr\Plugin\search_api\backend\SearchApiSolrBackend::getPropertyPathCardinality()

Computes the cardinality of a complete property path.

Parameters

string $property_path: The property path of the property.

\Drupal\Core\TypedData\DataDefinitionInterface[] $properties: The properties which form the basis for the property path.

int $cardinality: The cardinality of the property path so far (for recursion).

Return value

int The cardinality.

1 call to SearchApiSolrBackend::getPropertyPathCardinality()
SearchApiSolrBackend::getSolrFieldNames in src/Plugin/search_api/backend/SearchApiSolrBackend.php
Creates a list of all indexed field names mapped to their Solr field names.

File

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

Class

SearchApiSolrBackend
Apache Solr backend for search api.

Namespace

Drupal\search_api_solr\Plugin\search_api\backend

Code

protected function getPropertyPathCardinality($property_path, array $properties, $cardinality = 1) {
  list($key, $nested_path) = SearchApiUtility::splitPropertyPath($property_path, FALSE);
  if (isset($properties[$key])) {
    $property = $properties[$key];
    if ($property instanceof FieldDefinitionInterface) {
      $storage = $property
        ->getFieldStorageDefinition();
      if ($storage instanceof FieldStorageDefinitionInterface) {
        if ($storage
          ->getCardinality() == FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED) {

          // Shortcut. We reached the maximum.
          return FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED;
        }
        $cardinality *= $storage
          ->getCardinality();
      }
    }
    if (isset($nested_path)) {
      $property = $this->fieldsHelper
        ->getInnerProperty($property);
      if ($property instanceof ComplexDataDefinitionInterface) {
        $cardinality = $this
          ->getPropertyPathCardinality($nested_path, $this->fieldsHelper
          ->getNestedProperties($property), $cardinality);
      }
    }
  }
  return $cardinality;
}