Services
All ServicesDrupal DevelopmentIndustries
Products
AI Smart Quality AssistantPMO AI PlatformAll Products
Portfolio Company
About UsCareersFAQ
Blog Schedule a Consultation
Search API

Building an Alias Hierarchy Processor for Complex Multi-Level Structural Indexing

Charts and data structures on a desk

Enterprise sites hosting thousands of deeply nested pages need search that understands structure, not just titles. A small custom processor in the Search API ecosystem can turn URL aliases into a hierarchy that powers facets, breadcrumbs and scoped search.

The multi-level alias challenge

Standard indexes capture titles and fields without understanding where a page lives. On a ministry portal or university site, /services/licensing/commercial/renewals carries meaning: department, programme, audience. Out of the box, that meaning is lost at index time.

The approach: index every ancestor path

Instead of storing one alias, we store each prefix as a separate value of a multi-valued field:

/services
/services/licensing
/services/licensing/commercial
/services/licensing/commercial/renewals

Now "everything under licensing" is a simple filter on one indexed value, and a breadcrumb can be built from the same data without extra database queries.

The processor plugin

Search API processors that add properties implement two methods: one to declare the property, one to populate it per item.

namespace Drupal\my_search\Plugin\search_api\processor;

use Drupal\search_api\Datasource\DatasourceInterface;
use Drupal\search_api\Item\ItemInterface;
use Drupal\search_api\Processor\ProcessorPluginBase;
use Drupal\search_api\Processor\ProcessorProperty;

/**
 * @SearchApiProcessor(
 *   id = "alias_hierarchy",
 *   label = @Translation("Alias hierarchy"),
 *   description = @Translation("Indexes every ancestor segment of the path alias."),
 *   stages = {"add_properties" = 0},
 * )
 */
class AliasHierarchy extends ProcessorPluginBase {

  public function getPropertyDefinitions(?DatasourceInterface $datasource = NULL) {
    $properties = [];
    if (!$datasource) {
      $properties['alias_hierarchy'] = new ProcessorProperty([
        'label' => $this->t('Alias hierarchy'),
        'type' => 'string',
        'processor_id' => $this->getPluginId(),
        'is_list' => TRUE,
      ]);
    }
    return $properties;
  }

  public function addFieldValues(ItemInterface $item) {
    $entity = $item->getOriginalObject()->getValue();
    if (!$entity || !$entity->hasLinkTemplate('canonical')) {
      return;
    }
    $path = parse_url($entity->toUrl()->toString(), PHP_URL_PATH);
    $segments = array_filter(explode('/', trim($path, '/')));
    $fields = $this->getFieldsHelper()
      ->filterForPropertyPath($item->getFields(), NULL, 'alias_hierarchy');

    $prefix = '';
    foreach ($segments as $segment) {
      $prefix .= '/' . $segment;
      foreach ($fields as $field) {
        $field->addValue($prefix);
      }
    }
  }

}

Clickable breadcrumb performance

Because the hierarchy is stored in Solr (or the database backend), front-end applications can render breadcrumbs and "browse by section" facets straight from search results. The result is a fast experience across large document repositories without hitting database query limits.

Production tips

  • Re-index affected items when aliases change in bulk (for example after a Pathauto pattern update).
  • Handle language prefixes explicitly on multilingual sites.
  • Use the field as a facet source to give users a "narrow by section" control.

Planning search for a large content estate? Talk to our Drupal search specialists.

3P Technologies Engineering

Our team builds enterprise Drupal platforms, mobile apps and AI products from Amman, Jordan. About us

Keep reading

Related articles

All articles
Abstract visualisation of data being migrated between systemsMigration

Drupal 7 to Drupal 11 Migration: An Enterprise Checklist

Drupal 7 reached end of life in January 2025. If you are still on it, this phase-by-phase checklist covers what enterprise teams need to plan, migrate, validate and launch safely.

Read article
Need an enterprise implementation?

Put our engineers on your project.

Our team specializes in Drupal 11/12 platforms, Varnish performance engineering, multi-level data migrations and AI-powered delivery.