Drupal Must-Have Modules: Search API
What does the Search API module do?
The Search API module allows a site administrator to create flexible, detailed, robust search indexes that more semantically define what content is. It allows you to index your content and customize it in a way that makes sure everything appears when and where it is supposed to. It ensures that everything you want to appear in a search actually appears, making for a more effective search.
Photo by Louis Blythe
Why is Search API important?
Historically, there were a number of problems related to search in Drupal Core, and many of them had to do with performance. With Drupal Core, the system would index your content and then put that complete index in a database. As a result, searching was a slow process. You couldn’t get performant results. The user experience wasn’t great. It wasn’t very flexible and was not able to be fully customized.
When it comes to website performance problems, the majority are related to a website’s database — that’s where a lot of your processing is. In order to speed up a site and improve overall performance, the best thing to do is reduce the load on your database.
One of Drupal’s greatest strengths is its variety of modules that help users and developers to customize the platform to their specific needs. As part of an ongoing series, we asked Duo team members to spotlight one module they think is a must-have for any Drupal site.
Enter Apache Solr and Search API.
Search API came along as a way to give you more customization with how you build out the content you want indexed.
The module actually works best when integrated with Apache Solr, which exclusively indexes content. Search API shares what you want to index with Solr, and Solr will then be able to quickly return the results you’re looking for. What this means is you can speed up your search queries and, by customizing what you want to be indexed, take other unnecessary items off your server.
In Drupal 7, there were two ways of integrating with Apache Solr, both of which worked well. There was a module called “Apache Solr” that was specifically designed to work with Solr. There was also “Search API”, which was developed as a way to index content while being agnostic of the back-end search processor that was being used. This meant Search API was more flexible. It can still be used with the database if you want to do that. It can also integrate with Apache Solr.
In Drupal 7 there’s a mixture among the sites that use Apache Solr. Some use the Apache Solr module, while others use the Search API module. From Drupal 8 onward, both modules have been merged into the Search API module.
How can Search API impact site admins or users?
If you have a huge site with a lot of data, Search API is going to improve the user experience for visitors to your website. The module is best for any site with a lot of data, particularly data that you want users to be able to interact and search with. For example, a commerce site that features different items for purchase would greatly benefit from Search API.
Search API can also offer auto suggestion options, and it makes it possible for site admins to bias results — by that I mean that you can intentionally have a page appear at the top of a search.
Search API also features facets, which make it possible for a site to better understand the type of content you’re searching for. Think of how Amazon works. Let’s pretend you’re searching for a “BBQ grill”. Amazon displays a list of results, but then it also gives you an option to drill down more specifically. Instead of just searching for “BBQ grill,” you decide what you really want is a “Combination Grill-Smoker.” Amazon displays that list of results. Still not satisfied, you decide you still want to be more specific, so you specify what brand of combo grill-smoker you want.
If you run a Drupal site with Search API, you could use facets to offer that ability to drill-down into what a user is searching for.
What are some examples of Search API in action?
- West UC is an example of a Drupal 7 site that uses the Apache Solr module to interface with Apache Solr on the back-end. It has a great example of auto-completion in action. See the search box at the top-right of the page.
- The Episcopal Church is another Drupal 7 site that currently uses the Apache Solr module.
What is one tip you have to make Search API work even better for clients?
Aside from using Search API with Solr, I would make sure you have a good idea of what all your content is, including the types of content. Make sure you’ve thought through what content you have and how your content is related. If you have a sloppy structure, you’re going to have a sloppy search experience (you’ll also have poor SEO).
Have a good content model. This is what I have. This is how I want it to appear. That is what will help make for fast, effective search results.