How to Install Apache Solr on a Drupal 8 Website using SearchStax by Measured Search


Overview

SearchStax® by Measured Search® can be used to enable Apache Solr on a Drupal 8 website using Drupal's Search API and its Search API Solr plugins.

This article was based on a blog post by by Thomas Hada of Anant.

This example uses Drupal 8.3 and Solr 6.4.2. There is also a page for Drupal 7.

Basic Steps:

  1. Create a new deployment in SearchStax.
  2. Upload a custom configuration to your Solr Server.
  3. Install Drupal.
  4. Install the Search API and Search API Solr plugins.
  5. Configure the Search API Solr plugin.
  6. Add sample content.
  7. Optional - Manually Index Your Site.

Step 1: Create a New Deployment in SearchStax

Assuming you have already created a SearchStax account and do not already have a deployment set up, click on the Deployments tab and then click on the Create New Deployment button at the top. Enter a deployment name, and select the most appropriate region, plan, and Solr version for your needs. In this example we will be using Solr 6.4.2. SearchStax Solr Drupal

Once you create your deployment, you will see it in the Deployments dashboard. SearchStax Solr Drupal

Clicking on the name of the deployment will give you pertinent information about your deployment's servers. The Solr Load Balancer URL will take you to your Solr server dashboard. SearchStax Solr Drupal

Step 2: Upload a Custom Configuration to Your Solr Server

Download the Search API Solr plugin files: https://www.drupal.org/project/search_api_solr

Included in the Search API Solr download are several configurations in the solr-conf folder, with subfolders 4.x, 5.x, and 6.x for the respective Solr versions.
SearchStax Solr Drupal SearchStax uses Apache ZooKeeper for maintaining configuration information. Upload the appropriate configuration files via Zookeeper and create a new collection. If you have your Zookeeper script already, the two commands you will need are as follows:

Upload Configuration:

Linux:

> ./zkcli.sh -zkhost <zookeeper URL> -cmd upconfig -confdir <Solr configuration> -confname <configuration name>

Windows:

$ zkcli.bat -zkhost <zookeeper URL> -cmd upconfig -confdir <Solr configuration> -confname <configuration name>

Create New Collection:

Linux:

> curl '<Load Balancer URL>admin/collections?action=CREATE&name=<collectionName>&collection.configName=<configName>&numShards=1'

Windows:

$ curl.exe "<Load Balancer URL>admin/collections?action=CREATE&name=<collectionName>&collection.configName=<configName>&numShards=1" -k

Detailed instructions on uploading a new configuration and creating a new collection for a Solr deployment can be found at Solr-as-a-Service Quick Start.

Once complete, go into your Solr dashboard. There will be a newly created core based on the name of the collection name you defined when uploading the configuration. Make note of this core name. SearchStax Solr Drupal

Step 3: Install Drupal

If you do not already have one, there are many ways to create your own Drupal instance. Some web hosting services offer specialized integrations and setup options that help streamline the process. Here we used GoDaddy's Cloud Server services, which in a few clicks can create a hosted Drupal website. SearchStax Solr Drupal

Step 4: Install Search API / Search API Solr plugin

Go to your Drupal website and log in. SearchStax Solr Drupal SearchStax Solr Drupal

Open up a new tab in your web browser, then go to: https://www.drupal.org/project/search_api. Once there, scroll down to find the different download links. Right click on the appropriate download link to the compressed file, and copy the link address. SearchStax Solr Drupal

In your Drupal site, either navigate to the /admin/modules page or click the Extend tab at the top. Then click Install New Module. SearchStax Solr Drupal

Paste the link address copied earlier into the Install from a URL text field, and then click the Install button. SearchStax Solr Drupal

Once complete, you should see a confirmation message saying that the installation was complete. SearchStax Solr Drupal

If you see this, then you can install the Solr plugin for Search API: https://www.drupal.org/project/search_api_solr. Install this in the same way as above.

Before continuing, you may need to install the Search API Solr composer dependencies. See https://www.drupal.org/documentation/install/composer-dependencies for instructions on how to do this.

Next, you will need to enable the installed modules. Click Enable newly added modules, or click on the Extend tab. Scroll down to the section called Search to see new module settings. SearchStax Solr Drupal

Enable the following items: Search API, Solr search, and Solr Search Defaults.

Then click Install at the bottom of the page. You should see this confirmation: SearchStax Solr Drupal

Once complete, it is recommended to uninstall the Solr Search Defaults module, as it may affect performance. Uninstalling the module will not remove the provided configurations.

Step 5: Configure the Search API Solr Plugin

Now that the modules have been enabled, click on the Configuration tab. Look for section SEARCH AND METADATA and click on Search API to configure it.
SearchStax Solr Drupal

Once there, click Add Server. SearchStax Solr Drupal

Give your server a name, make sure the Backend is set to Solr, and configure your Solr Backend. Check that HTTP protocol is set to "https", the Solr host and Solr port are correct, and you set the Solr core that was created after uploading your Solr configuration. SearchStax Solr Drupal SearchStax Solr Drupal

If your configuration settings are valid, you will see a message saying that the information was saved successfully. SearchStax Solr Drupal

Next you will need to define an index. In the Search API configuration screen, click on Add Index. SearchStax Solr Drupal

Give your index a name, and select the data sources you wish to index. For this example, select Comment and Content. Also, at the bottom of the page make sure that you select the Server created earlier. SearchStax Solr Drupal SearchStax Solr Drupal

Step 6: Add Sample Content

Install the Devel plugin using the same method as described in Step 4: https://www.drupal.org/project/devel. Then, enable Devel and Devel generate. SearchStax Solr Drupal

You will see new options in multiple menus. Go to Manage > Configuration, and scroll down to the Development section. Here you have options to Generate content via Devel. SearchStax Solr Drupal

Click on Generate Content.

Select a Content Type and enter the number of nodes. For example, selecting Article and typing "20" nodes will produce 20 new articles filled with dummy data. SearchStax Solr Drupal

Step 7: Optional - Manually Index Your Site

A cron job will periodically index your site automatically, but if you want to see your results immediately go to the Search API configuration screen and click on the index created earlier. At the bottom, click on the Index now button. SearchStax Solr Drupal

After you begin, you will see a progress bar. Once it reaches 100%, you will get a success message. SearchStax Solr Drupal

After your site has been indexed, you can view and query the data in Solr. SearchStax Solr Drupal

Congratulations! You have now customized your Drupal website to allow for content to be indexed in your SearchStax Solr deployment.