You are here

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

Checks if a field is (potentially) hierarchical.

Fields are (potentially) hierarchical if:

  • they point to an entity type; and
  • that entity type contains a property referencing the same type of entity (so that a hierarchy could be built from that nested property).

Return value

bool

See also

\Drupal\search_api\Plugin\search_api\processor\AddHierarchy::getHierarchyFields()

1 call to SearchApiSolrBackend::isHierarchicalField()
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 1534

Class

SearchApiSolrBackend
Apache Solr backend for search api.

Namespace

Drupal\search_api_solr\Plugin\search_api\backend

Code

protected function isHierarchicalField(FieldInterface $field) {
  $definition = $field
    ->getDataDefinition();
  if ($definition instanceof ComplexDataDefinitionInterface) {
    $properties = $this->fieldsHelper
      ->getNestedProperties($definition);

    // The property might be an entity data definition itself.
    $properties[''] = $definition;
    foreach ($properties as $property) {
      $property = $this->fieldsHelper
        ->getInnerProperty($property);
      if ($property instanceof EntityDataDefinitionInterface) {
        if ($this
          ->hasHierarchicalProperties($property)) {
          return TRUE;
        }
      }
    }
  }
  return FALSE;
}