Archive for March, 2014

Drupal Search API configuration with views

With Drupal 7 there is now the search API. Apart from the existing database (that uses the same DB as drupal to index with) and Solr integration there are a few other backend options available too. As the open source community is quite prolific, a few supporting modules to allow fuzzy searching, multi index searching, saved searches, autocompletion, attachment indexing and more have sprung up. See the Search API project page for more detail.

When we started working on the Kamusi project – a dictionary for african languages – early in 2012, we decided to aim lower at first and set up plain old database indexing. The joy being that when the userbase, database of dictionary terms and thus the load increases, we can simply plug in a new server. Like Solr. Joy!

Here’s how we set up the database indexing:

  1. Download and Install the Search API module. It requires the Entity API module as well as Views to build your search results with – That’s right, no more hacking the Search results page to get pretty! To be able to use your database as an index, also download and install Database search.
  2. Enable the Search API, Database Search and Search views modules.
  3. Go to admin/config/search/search_api. This is where your search servers and indexes are listed. The servers dictate where and how indexes reside, while indexes are the where the actual search data reside. We decided to create two indexes: one for word definition, and another for translation. We keep seperate nodes for each translation of a word, as Drupal multi-language is still a bit of a battlefield.
  4. Click “Add server”. Enter a name for your server (“Default database” is as good as any, I guess). Select “Database service” as the Service class and click “Create server”.
  5. Go back to admin/config/search/search_api and click “Add index”. Enter the name of the index (Eg. “Definition index”) and select the entity type you would like to index. Node is generally a good bet. Select the server we’ve created in the previous step, and leave the rest as is. If you have a large dataset, only enable “Index items immediately” after you’ve got your first set of data manually indexed. Set the chron batch size, careful not to make it too big and crash your cron runs (about 1000). Rather leave it at 50, for now. Click “Create index”.
  6. Select the fields you would like to index. You can index other details of a field by using the “Add related fields” fieldset below the form, particularly useful if you are using relations, or node references. Click “Save”.
  7. Index your existing data by running cron (in our case, a LOT), or on admin/config/search/search_api click edit>status and clicking “Index now” a few times (in our case, a LOT). Edit your index and enable “Index items immediately”.
  8. Go to admin/structure/views/add and create your search view (You know the drill) by selecting your index in the “Show” dropdown.
  9. This view will now show everything that is in your index. Add filter criteria to the view and expose some to the user. This this will become your search form.
  10. Add a page display so that your users may view search results. Edit the exposed form settings and change your submit button text. You may add a search block to your site by setting “Expose form in block” to “yes” under the exposed form settings.

Joy! Hopefully you will now have a pretty search form that will serve your users with pretty and relevant results!

Advertisements

Leave a comment