Solr is a great option for handling search tasks, allowing you to reduce the load on your database. You can easily integrate the Drupal Search API Solr module into your Drupal application by following these instructions.
DDEV Local Setup
Let's begin with ddev. Are you using ddev on your local machine? You can check out more information here: https://github.com/ddev/ddev-solr
#settings.ddev.php
$config['search_api.server.solr_server'] = [
'backend_config' => [
'connector' => 'solr_cloud_basic_auth',
'connector_config' => [
'host' => 'solr',
'path' => '/',
'core' => 'maincore',
'port' => '8983',
'username' => 'solr',
'password' => 'SolrRocks'
]
]
];
Whenever you modify the solr schema on ddev, you need to run the following to import the schema files.
ddev drush --numShards=1 search-api-solr:upload-configset solr_server
You can check your Solr settings using drush:
drush cget search_api.server.solr_server --include-overridden
Platform.sh / Upsun
From the Drupal Search API configuration page "admin/config/search/search-api" you will create a server connection to the Solr service which the credentials are then saved in the database.
You will need to override these connection details to avoid configuration import issues.
#settings.platformsh.php
if ($platformsh->hasRelationship('solrsearch')) {
$solr_credentials = $platformsh->credentials('solrsearch');
$config['search_api.server.solr_server'] = [
'backend_config' => [
'connector_config' => [
'connector' => 'standard',
'host' => $solr_credentials['host'],
'port' => $solr_credentials['port'],
'core' => substr($solr_credentials['path'], 5) ? : 'collection1'
],
],
];
}
Please download the `config.zip` from the Solr Server settings page at "admin/config/search/search-api/server/solr_server".
After that, you can save these files in your git repository in a folder named `.platform/solr`.
#.platform.app.yaml
relationships:
solrsearch: "searchsolr_v1:main"
#services.yaml
searchsolr_v1:
type: solr:9.4
disk: 1024
configuration:
cores:
maincore:
conf_dir: !archive "solr/"
endpoints:
main:
core: maincore
I prefer to label my services with an `_v1`, which I update to prompt my services to rebuild from the ground up. Please note: This will remove your service container and rebuild it completely.
Happy Searching!