Drupal / Search API Solr
Note about Administrative actions
The Search API Solr module performs 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 email@example.com to learn more.
In this guide, we’re going to cover the basics of setting up a Websolr index to be used with Drupal 7 and the Search API Solr module. A few points to note before we get started:
- This example uses Drupal 7.22 and Search API Solr version 7.x-1.1. Your versions may vary; as long as the major versions are the same, you can reliably use this guide.
- This guide is not meant to be an exhaustive tutorial on all of the things the Search API Solr module can do. The goal here is to get you up and running quickly, then let you tune things as necessary.
- If you run into issues while following this guide, make sure to check the “Troubleshooting” section at the bottom and see if a solution is addressed there.
Make sure you navigate to
admin/modules and verify that the Search API Solr module and its related modules have been activated:
Make sure to disable the core Search module:
That’s all you need to get started! Next, we’ll configure the Websolr index that will hold your documents.
Setting up the Websolr index
Next, you’ll want to add a new slice to your Websolr account. Give your index a descriptive name, select the server group nearest to your application, then select “Drupal 7 (Search API Solr)”:
When this form has been filled out, click “Create Index.” Afterwards, you will be redirected to the slice dashboard:
Setting up the Search API Solr Module
Once your Websolr index is up and running, it’s time to configure the Search API Solr module. Navigate to
admin/config/search/search_api in your Drupal site and you should see something like this:
The first step to configuring Search API Solr is to tell the module about your Websolr server. Click on the link marked “Add Server” and give your your server a helpful name and description. Select “Solr service” from the “Service class” dropdown and fill out the information as below (leave the “Basic HTTP Authentication” and “Advanced” fields alone):
Click “Create server.” If everything was input correctly, you should see something like this:
Now, return to
admin/config/search/search_api We need to add a new index; we can do so by clicking on the “Add index” link and using the following information in the subsequent form:
Keep in mind that this tutorial is not going to cover all of the possible configurations. You will need to evaluate your needs and adapt the above settings as necessary. As it stands, this tutorial will involve indexing nodes only. Once you have saved the index, you should see something like this:
Again, we’re not going to cover everything. Just enough to get our basic search up and running. I made the following selections to get the basic node elements indexed, but you will need to evaluate which fields are important for your specific application. Fortunately, if you make a mistake or want to change things later, you can do so:
Once you have configured your fields for the index, save your progress and you will see something like this:
You don’t strictly need to do anything with the workflow here. You may want to save any of these changes for later though, AFTER you have successfully indexed and searched documents. That will help you narrow down your troubleshooting if necessary.
Now, navigate back to
admin/config/search/search_api and click on Edit > Status for the Websolr index that you have created. You should see this:
Leave the advanced settings alone and simply click on “Index now.” That will send all of your nodes to the new Websolr index. You should get a neat little progress bar along the way. Once the indexing operation has completed, you should get a message like this:
If you got any error messages, go back and check your settings. As a last step, I would recommend returning to
admin/config/search/search_api and deleting the “Default node index” that came bundled with the module if you have not already done so.
Setting up the Search API Pages Module (optional)
The Search API module does NOT provide any out of the box searching capabilities. Rather, it provides an API for other modules to simplify their own Solr searching. This means that you will either need to write your own module, tailored to your specific needs, or you will need to use an existing module. In this tutorial, I am using Search API Pages to provide a search page. This is optional for you, but it is a good tool to use at first because it will help you verify that everything is working.
admin/config/search/search_api, click on the “Search Pages” tab, then click on the “Add search page” link. Alternatively, you could simply navigate to
admin/config/search/search_api/page/add. Fill out a form like this:
Once you have created the page, you will be able to customize how the query is processed and how the results are returned. You can pretty much just leave the defaults here:
Click on “Create Page” and you should get a message like this:
Checking on your index
After the Search API Solr module has indicated a successful indexing of your documents, you can navigate to your Websolr URL and append “/select” to it. For me, this was
http://ec2-west.websolr.com/solr/9ea6b15fcc9/select This will return the first set of documents in your index:
You can also look at the slice summary, which will indicate the status of your index and how many documents are present:
To test Drupal, pick out a keyword that you can see in your index. Since my nodes were all randomly-generated, I grabbed the word “dolor” because it seemed to come up a few times. Go to your Drupal search (if you created a Search Page in the previous section, navigate there) and enter your chosen keyword. If everything is configured correctly, you should get a set of results:
I get a 401 Unauthorized error when I try to index my documents
You have probably enabled authorization on this index. Making changes (writes, updates, deletes) to your index requires that your HMAC key be included in the request header. The Search API Solr module does not have the capability of crafting a request in this way. There are three solutions: disable advanced authorization, hack the module to include the HMAC header and hard-code your key, or write a patch for the module that adds this cabability for end users and submit it to the maintainer for consideration.