Search API Exclude Entity
Provides a field type and Search API processor to selectively exclude entities from being indexed in Search API indexes.
search_api_exclude_entity
Install
composer require 'drupal/search_api_exclude_entity:^3.0'
composer require 'drupal/search_api_exclude_entity:^2.0'
composer require 'drupal/search_api_exclude_entity:8.x-1.4'
Overview
Search API Exclude Entity is the Drupal 8+ successor to Apache Solr Node Exclude module. It enables site administrators to exclude specific nodes and other entities from being indexed in search indexes configured using the Search API framework.
The module uses a custom field type approach, providing a dedicated field type, widget, and formatter for controlling the exclude status on entities. This architecture offers several advantages: configurable field position, label, and description per entity type/bundle; support for multiple exclude fields on the same entity bundle for different search systems or indexes; and automatic Views integration without custom plugins.
When an entity has its exclude field checked, the Search API processor prevents that entity from being added to the search index during indexing operations.
Features
- Custom 'Search API Exclude Entity' field type that stores a boolean value indicating whether an entity should be excluded from search indexes
- Configurable field widget with options for checkbox label text and whether to display in a details container in the 'Advanced' section
- Field formatter extending the core boolean formatter with 'Yes/No' display format
- Search API processor plugin that filters out entities marked for exclusion during the 'alter_items' indexing stage
- Processor configuration allowing selection of which exclude fields to use per entity type for each search index
- Support for multiple exclude fields per entity bundle, enabling exclusion from different search indexes independently
- Permission-based access control for editing the exclude status on entities
- Integration with Single Content Sync module for import/export of exclude field values
- Views integration out of the box without requiring custom plugins
Use Cases
Exclude specific landing pages from search
A marketing team creates temporary promotional landing pages that should not appear in the site's search results. By adding the Search API Exclude Entity field to the landing page content type, editors can check the exclude option on each page they want to hide from search while keeping the page published and accessible via direct URL.
Multiple search indexes with different content
A site has both a public search and an internal staff search, each using different Search API indexes. By adding two separate exclude fields to content types and configuring each index's processor to use the appropriate field, editors can independently control whether content appears in the public search, the staff search, or both.
Exclude content with noindex meta tags
A site already uses the Metatag module to set robots noindex on certain pages. Using the search_api_exclude_entity_metatag submodule, these pages are automatically excluded from Search API indexes, ensuring consistency between what external search engines and internal search show.
Exclude draft or unpublished-equivalent content
Using the search_api_exclude_entity_by_field submodule, a site can exclude content based on field values like a 'status' dropdown set to 'Draft' or 'Review', providing more granular control beyond the standard published/unpublished state.
Permission-controlled exclusion for editorial workflow
Only senior editors should be able to exclude content from search. By granting the 'edit search api exclude entity' permission only to the 'Senior Editor' role, junior editors can create and publish content but cannot affect search visibility.
Tips
- Add the exclude field to your entity type before creating the Search API index to ensure the field appears in processor configuration immediately.
- Use descriptive field labels for the checkbox to help editors understand which search index will be affected, especially when using multiple exclude fields.
- Consider placing the exclude field in the 'Advanced' section using the widget's 'Use details container' setting to keep the main form clean.
- When testing, remember to re-index after making changes to exclude settings - the exclusion only happens during the indexing process.
- For sites with many content types, you can reuse the same field across bundles - the processor will detect all instances automatically.
- The module works with any Search API backend including Solr, Elasticsearch, and Database Search.
Technical Details
Permissions 1
Hooks 2
hook_form_field_storage_config_edit_form_alter
Hides and disables the cardinality container when editing field storage for Search API Exclude Entity fields, as the field only supports a cardinality of 1.
hook_entity_field_access
Controls edit access to Search API Exclude Entity fields based on the 'edit search api exclude entity' permission. Users without this permission cannot edit the exclude field on entity forms.
Troubleshooting 4
After checking the exclude field on entities, you must re-index the content for changes to take effect. Go to the Search API index and click 'Re-index' or use Drush command 'drush sapi-r index_name'. Also verify that the Search API Exclude Entity processor is enabled and the correct fields are selected in the processor configuration.
Ensure you have the 'edit search api exclude entity' permission. The field access is controlled by this permission, and users without it will not see the field on forms.
Make sure you have added a 'Search API Exclude Entity' field to at least one entity type/bundle that is included in your search index's datasources. The processor only shows fields from entity types that are configured as datasources in the index.
Check the widget settings and ensure 'Use details container' is enabled. Also verify your form display settings place the field correctly. If using a theme that doesn't render the 'advanced' form group, the field may appear elsewhere.
Security Notes 2
- The 'edit search api exclude entity' permission controls who can modify exclusion settings. Grant this permission carefully as it affects content visibility in search results.
- Excluding content from search does not prevent direct access to the content - it only affects search index visibility. Use other access control mechanisms if you need to restrict content access entirely.