Drupal's default core search does have limitations in the way it searches a database and if there is increased search traffic it can affect response times. The reason for this is that the search POST requests are making database calls. Memcache is an option in this circumstance if the search queries are the same. Excessive once-off query search queries will have negative effects on an application as there is no way to offset the computing power needed to protect the database.
Core search is relevant if your website needs a basic search with no demand for granular configuration and exorbitant database transactions. Search core overview on Drupal.org does discuss what functionality it has by default:
https://www.drupal.org/docs/8/core/modules/search/overview
The search module lets users search for specific content on your site. You can search both for users and for particular words.
Drupal's Contributed Search API
Drupal's contributed project space does extend search using the Search API this module provides a developer the ability to extend the site's search capabilities in a granular way. Some options open to an organisation's development team are mentioned in the list below.
- Control over website search with granular configuration
- Caching, Replication, Distributed search.
- Indexing content wanted by the organisation.
- Moving computing power to another service.
The search API framework will allow the team to expand Drupal's capabilities to extend search but does not have the functionality to connect to a search service that will allow increased configuration.
Installing the Search API framework
Installing the default search API module using Drupal Composer and Drush is the best practice and is not only encouraged by Drupal.org but all major industry leaders. The example command below will enable the Search API module (for the latest version of the module navigate to the Search API project page).
Composer command
composer require 'drupal/search_api:^1.28'
Drush command
drush en search_api -y
Adding a Search API backend
If you navigate to this URL on your website `/admin/config/search/search-api/add-server`. It will display an error like the following:
There are no backend plugins available for the Search API. Please install a module that provides a backend plugin to proceed.
There are several contributed backend plugin options available to a Drupal application on Drupal.org. The server backends and features page state these current options. If the application is expecting a lot of search traffic requests it would be best to move onto another service like Solr and not use the database.
- Database Search (contained directly in the “Search API” project)
- Search API Solr (Documentation)
- Elasticsearch Connector
- Search API OpenSearch
- Algolia
- Xunsearch
- Coveo
- Search API MeiliSearch
- Search API Sajari (no searching, no optional features supported)
Installing Search API Solr Plugin
To install Solr Plugin using composer to find the correct version navigating to the Search API Solr project page will be necessary to check your version of Drupal by using `drush status`. Then using Drush enable the module using the second command below.
Composer command
composer require 'drupal/search_api_solr:^4.2'
Drush command
drush en search_api_solr
After installation navigates via the browser to this url `admin/config/search/search-api/add-server`. You will need to get the Solr service connection information from the vendor of your choice. If the team is testing a Solr locally Drupal.org has an example of how to install Solr and create a connection with your Drupal environment.
Solr companies will often provide modules that will automatically configure a connection to a Solr Index. As an example Acquia accommodates has the acquia_search module. Which is very useful when developing on Acquia Cloud. In this circumstance, all a developer needs are the vendors' documentation to install and configure the functionality and would need to create a manual connection.
Now using Drush, run the following command and if you're using the Acquia Search module you will see the following `ID` show. If the Solr connection process was completed by another vendor's module or manually the `ID` and `Name` will likely be different.
drush search-api:status --------------------- -------------------------- ------------ --------- ------- ID Name % Complete Indexed Total --------------------- -------------------------- ------------ --------- ------- acquia_search_index Acquia Search Solr Index - 0 0 --------------------- -------------------------- ------------ --------- -------