Drupal / Apachesolr

Deprecation Notice

The Apachesolr module integrates Solr search into Drupal sites. This module is available for Drupal 7 only, and has been superseded in Drupal 8+ by the Search API Solr module.

Note about Administrative actions

The Apachesolr module does some checks against Solr's administrative endpoint in order to collect information about the servers. This information is not accessible on Websolr's multi-tenant subscriptions for security reasons. However, this does not affect your ability to index and search your data.

If you are seeing HTTP 404 or 401 errors in your logs and request stream, this is not necessarily indicative of a problem. If the endpoint throwing the error is something like /admin/system, then there is no cause for alarm. These errors can be safely ignored, and will not impact your ability to use Websolr.

If you would like access to the administrative endpoints, we can accommodate on one of our Business subscriptions. Send us an email at support@websolr.com to learn more.

Getting Started

The first step to adding Solr search to your Drupal site is to sign up or sign in to Websolr and create an index:

Give your index a descriptive name, then select a geographic region that is as close as possible to where the Drupal site is hosted. Then select the "Drupal 7 (Apachesolr)" configuration. Finally, click on the "Create Index" button. This will create a new Solr index configured with the Apachesolr settings.

Once the new index has been created, you will be redirected to the dashboard:

Make note of the index URL, which will be needed later.

Configure Drupal

You will need to install the Apachesolr project (see the documentation for that here). Open up the Modules menu and ensure that the module is enabled:

To set up the module, navigate to Configuration > Search settings > Apachesolr Search. Click on the Settings link to set up the Solr connection:

For the Solr server URL, use the URL from your Websolr dashboard. You can also change the Description field to something a little more descriptive. Select the checkboxes about Commit settings and click "Save."

You can also optionally click on the "Test connection" button. You should be able to reach the Solr server and get a message like this:

Index Your Content

Navigate to the "Default Index". This will show some metadata, offer some actions, and settings:

Connection Error May Occur

The module attempts to pull administrative information about the Solr server when rendering this view. Administrative endpoints are protected on Websolr for security and privacy reasons, and these requests will fail. As a result, the display indicates an error. This has no impact on your ability to index and query documents from Solr.

Select the node types that you'd like Solr to index and click Save.

By default, the module will index a fixed number of nodes during each cron run. When you are setting this up for the first time, you will probably want to push all the nodes into Solr. Click on "Index all queued content". This will bring up a confirmation option:

Click on "Index all remaining" to add your data to Websolr.

When the process completes, you may see an error like this:

This is related to the note above. A call to an administrative endpoint has been blocked, which raises this exception. However, it has not prevented the data from being indexed.

If you want to confirm that the data has been indexed into Solr, you can append "/select" to your Solr URL, which will return metadata about the index and a sample of the nodes that were indexed:

# The wt=json and indent=true parameters are not required, but improve readability:
curl -s "https://us-east-1.websolr.com/solr/a1b2c3d4e5f/select?wt=json&indent=true"  
{
  "response":{"numFound":1,"start":0,"docs":[
      {
        "id":"606yh2/node/1",
        "site":"https://...",
        "hash":"606yh2",
        "entity_id":1,
        "entity_type":"node",
...
Query Your Content

Now that the data is in Solr, Drupal needs to be configured to default to Solr. Navigate to Configuration > Search settings, which will bring up a menu for controlling how Drupal performs search:

Ensure that the Apachesolr module is active and the default search engine, and save. You may optionally want to log searches for business intelligence reasons, although this may have performance implications.

You should now be able to query your content through Drupal:

There are many other settings and modules that extend Apachesolr, which can be found on the module page.