Search API Solr
Provides an Apache Solr backend for the Search API module, enabling powerful full-text search capabilities with advanced features like faceting, highlighting, autocomplete, and multilingual support.
search_api_solr
Install
composer require 'drupal/search_api_solr:^4.3'
Overview
Search API Solr is a comprehensive integration module that connects Drupal's Search API with Apache Solr search servers. It provides a robust backend implementation for indexing and searching Drupal content using Solr's powerful full-text search capabilities.
The module supports various Solr deployment modes including single-server installations and Solr Cloud clusters. It automatically generates Solr configuration files (schema.xml, solrconfig.xml) tailored to your Drupal setup and supports extensive customization through configuration entities for field types, caches, request handlers, and request dispatchers.
Key capabilities include multilingual search with language-specific field types, highlighting of search results, faceted search integration, autocomplete suggestions, spellcheck functionality, More Like This recommendations, streaming expressions for advanced queries, and multisite indexing support.
Features
- Implements Search API backend plugin for Apache Solr servers with support for both single-server and Solr Cloud deployments
- Provides four connector types: Standard, Basic Auth, Solr Cloud, and Solr Cloud with Basic Auth for different authentication and deployment scenarios
- Automatic generation of Drupal-specific Solr configuration files (config.zip) including schema.xml, solrconfig.xml, and language-specific field types
- Multilingual search support with language-specific field types and analyzers for over 50 languages
- Highlighting processor integration that retrieves highlighted snippets directly from Solr for better performance and accuracy
- Faceted search integration through the Facets module with support for hierarchical facets and date ranges
- Autocomplete functionality with three suggestion modes: Terms, Spellcheck, and Suggester (via search_api_solr_autocomplete submodule)
- More Like This (MLT) support for finding similar content based on document similarity
- Spellcheck and query suggestion capabilities for improved search experience
- Streaming expressions support for complex analytical queries in Solr Cloud environments
- Multisite indexing support allowing multiple Drupal sites to share a single Solr index
- Configurable Solr field types, caches, request handlers, and request dispatchers as config entities
- Index finalization hooks for applying late modifications to indexed documents before searches
- Parallel indexing support for faster content processing (via Drush command)
- Comprehensive event system for customizing query building, document indexing, and result processing
- Administration submodule for uploading configsets, reloading cores/collections, and field analysis
Use Cases
Enterprise Content Search
Implement a powerful site-wide search for enterprise websites with thousands of content items. Use Solr's efficient indexing and query capabilities to provide sub-second search results with faceted navigation for filtering by content type, date, author, taxonomy terms, and custom fields.
Multilingual Website Search
Configure language-specific search for multilingual Drupal sites. Search API Solr provides language-specific field types with proper stemming, stop words, and analyzers for over 50 languages, ensuring users find content in their language with language-appropriate text analysis.
E-commerce Product Search
Build a comprehensive product search with faceted filtering, price range facets, attribute filters, and relevance tuning. Use Solr's boosting capabilities to promote featured products and adjust relevance based on popularity, recency, or custom business rules.
Search-as-you-type Autocomplete
Implement responsive autocomplete suggestions using the search_api_solr_autocomplete submodule. Configure terms-based suggestions for fast prefix matching, spellcheck suggestions for typo correction, or Solr's suggester for context-aware completions.
Multisite Unified Search
Create a unified search across multiple Drupal sites sharing a single Solr index. Users can search content from all sites simultaneously or filter to specific sites using the multisite document datasource and site hash filtering.
High-availability Search Cluster
Deploy a fault-tolerant search infrastructure using Solr Cloud. Configure multiple shards for horizontal scaling and replication for high availability. Use the admin submodule to manage configsets and collections directly from Drupal.
Document Repository Search
Build a searchable document repository by integrating with Search API Attachments. Solr extracts text from PDFs, Word documents, and other file formats using Apache Tika, making document contents fully searchable.
Related Content Recommendations
Use Solr's More Like This (MLT) feature to display related content blocks. Configure MLT parameters in the index settings to find similar articles based on shared terms, taxonomy, or custom similarity criteria.
Tips
- Use Solr Cloud mode for production deployments - it provides better scalability, fault tolerance, and easier configuration management through configsets.
- Enable the search_api_solr_admin submodule for Solr Cloud deployments to manage configsets directly from the Drupal admin UI.
- Disable Search API processors that perform tokenizing and stemming - Solr handles these better through its language-specific analyzers.
- Keep the HTML Filter and Highlighting processors enabled - they work well with Solr's highlighting capabilities.
- Use 'Retrieve result data from Solr' with 'Skip item access checks' in Views for better performance when access control is handled during indexing.
- Generate a new config.zip and redeploy whenever you add new languages or custom field types to your Drupal installation.
- Use the Field Analysis tool in the admin submodule to understand how text is tokenized and analyzed by different field types.
- For development, use the jump-start docker-compose files included in the module for quick Solr setup.
- Set Solr parameters directly in Search API queries using the 'solr_param_' prefix, e.g., `$query->setOption('solr_param_mm', '75%')`.
- Use streaming expressions for complex analytical queries in Solr Cloud - they enable operations like joins, aggregations, and machine learning integration.
Technical Details
Admin Pages 12
/admin/config/search/search-api/server/{server_id}
Configure the Solr backend settings including connector type, connection parameters, and advanced options. Also provides access to download generated Solr configuration files.
/admin/config/search/search-api/server/{server_id}/files
View and download individual Solr configuration files generated for this server. Provides access to download specific XML configuration files or the complete config.zip.
/admin/config/search/search-api/server/{server_id}/solr_field_type
Manage custom Solr field types used by this server. Field types define how text is analyzed and indexed, including language-specific configurations.
/admin/config/search/search-api/server/{server_id}/solr_cache
Configure Solr caching settings including query result cache, filter cache, and document cache for optimal search performance.
/admin/config/search/search-api/server/{server_id}/solr_request_handler
Manage Solr request handlers that define how different types of search requests are processed (select, suggest, mlt, spell, etc.).
/admin/config/search/search-api/server/{server_id}/solr_request_dispatcher
Configure Solr request dispatchers that handle HTTP request processing and caching headers.
/admin/config/search/search-api/server/{server_id}/solr-admin/upload-configset
Upload a generated Solr configset directly to a Solr Cloud cluster. For new collections, also allows specifying sharding and replication settings.
/admin/config/search/search-api/server/{server_id}/solr-admin/reload-core
Force the Solr server to reload the core configuration. Use this after manually updating configuration files.
/admin/config/search/search-api/server/{server_id}/solr-admin/reload-collection
Force the Solr Cloud server to reload the collection configuration across all nodes.
/admin/config/search/search-api/server/{server_id}/solr-admin/delete-collection
Delete a Solr Cloud collection. Warning: This permanently removes the collection and all indexed data.
/admin/config/search/search-api/server/{server_id}/solr-admin/field-analysis
Test how text is analyzed by different Solr field types. Useful for debugging search behavior and understanding tokenization, stemming, and filtering.
/admin/config/search/search-api/index/{index_id}
Configure Solr-specific settings for a Search API index including finalization, highlighting, More Like This, and multilingual options.
Permissions 2
Hooks 7
hook_search_api_solr_query_alter
Deprecated in 4.2.0. Use PreQueryEvent instead. Allows altering the Solarium query before execution.
hook_search_api_solr_converted_query_alter
Deprecated in 4.2.0. Use PostConvertedQueryEvent instead. Allows modifying the query after conversion to Solr expression.
hook_search_api_solr_field_mapping_alter
Deprecated in 4.2.0. Use PostFieldMappingEvent instead. Allows altering field name mappings.
hook_search_api_solr_documents_alter
Deprecated in 4.2.0. Use PostCreateIndexDocumentsEvent instead. Allows altering Solr documents before indexing.
hook_search_api_solr_search_results_alter
Deprecated in 4.2.0. Use PostExtractResultsEvent instead. Allows altering search results returned from Solr.
hook_search_api_solr_finalize_index
Deprecated in 4.2.0. Use PreIndexFinalizationEvent instead. Apply finalization commands before the first search.
hook_search_api_solr_config_files_alter
Deprecated in 4.2.0. Use PostConfigFilesGenerationEvent instead. Alter generated Solr configuration files.
Drush Commands 10
drush search-api-solr:get-server-config
Downloads the generated Solr configuration files for a server as a ZIP archive.
drush search-api-solr:reinstall-fieldtypes
Deletes all Solr field types and reinstalls them from their YAML configuration files.
drush search-api-solr:install-missing-fieldtypes
Installs any missing Solr field types from their YAML configuration files.
drush search-api-solr:finalize-index
Runs finalization operations on one or all enabled search indexes.
drush search-api-solr:execute-raw-streaming-expression
Executes a raw streaming expression on a Solr Cloud index.
drush search-api-solr:index-parallel
Indexes items using parallel threads for improved performance.
drush search-api-solr:reload
Reloads a Solr core or collection to apply configuration changes.
drush search-api-solr:upload-configset
Uploads a configset to Solr Cloud and reloads or creates the collection.
drush search-api-solr:delete-collection
Deletes a Solr Cloud collection.
drush search-api-solr:delete-all
Deletes ALL documents from a Solr server across all indexes.
Troubleshooting 8
Enable 'Retrieve results for this site only' in the server's Multi-site compatibility settings, or ensure proper site hash filtering is configured in your queries.
This indicates the Solr core was created without the proper Drupal-specific configset. Download the config.zip from the server page and redeploy it to Solr, then reload the core.
After modifying Solr configuration entities (field types, caches, etc.), download the new config.zip and redeploy to Solr. Then reload the core/collection using the admin submodule or drush solr-reload command.
Add the appropriate language-specific Solr field type configuration. If no language-specific configuration is available, the module falls back to the language-undefined field type. Enable 'Suppress warnings about missing language-specific field types' in advanced settings if this is acceptable.
Disable Views caching or use 'Search API (time based)' cache. For tag-based caching, enable 'Finalize index before first search' and 'Wait for commit after last finalization' in index settings.
Ensure the suggester is built by running cron or manually triggering a suggester build. Check that the request handler for suggestions is not disabled in the backend configuration.
Reduce the 'Default result rows' setting in advanced server configuration. High values combined with multiple shards can exceed memory limits as Solr reserves the row limit per shard for result sorting.
If the parallel indexing command was interrupted, run 'drush search-api-solr:reset-empty-index-state' to clear the blocking state that prevents deletes for up to one hour.
Security Notes 6
- Solr servers should NOT be exposed to the public internet. Use firewall rules or network configuration to restrict access to the Solr server from your web server only.
- Use HTTP Basic Authentication (BasicAuth connectors) when Solr must be accessible over a network, and always use HTTPS in production.
- The 'execute solr admin task' permission grants powerful capabilities including collection deletion - assign only to trusted administrators.
- Be cautious with multisite indexing - content from one site may be visible to users on another site if proper site hash filtering is not configured.
- Review indexed content to ensure sensitive data is not inadvertently exposed through search results or facets.
- The config.zip contains configuration files that reveal your index structure - handle it securely and don't expose it publicly.