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.