Faceted Search in Drupal 8: Using Search API Solr and Facets

  • 6 minute read

When module authors decide to port their modules to a new major version of Drupal (e.g. 6 to 7, or 7 to 8), they often take the time to rearchitect the module (and sometimes an entire related ecosystem of modules) to make development more efficient, clean up cruft, and improve current features.

If you've ever used Apache Solr as a search engine for your Drupal site, you know there were two modules that could power search functionality: Apache Solr Search and Search API Solr. Both modules worked great in Drupal 7, and both provided many powerful features for modern search, like fast full-text search and indexing, search facets, and autocomplete. Unfortunately, having two separate modules and architectures meant many add-on features were developed twice.

There were some efforts to consolidate things like schema configuration, so people would have an easier time switching between the two modules, but on the whole, the development efforts for Solr in Drupal 7 have been fragmented, so a lot of people (myself included) were torn between some of the benefits of each module and it's ecosystem.

Apache Solr Search provided a nicer out-of-the-box experience and required less configuration for standard search functionality. Search API Solr was much more flexible, pluggable, and configurable, but required more initial effort to set up. In Drupal 8, both module's maintainers decided to team up and consolidate efforts behind Search API and Search API Solr.

This means you no longer have to pick between two excellent modules—there's now one even better module. And module contributors who want to add on functionality don't have to decide to support one ecosystem or split efforts between the two, so all the related modules (like Facet API [now Facets] and Facet API Pretty Paths, Search API Autocomplete, etc.) can focus on one target instead of two. You can read more of the history of Apache Solr's relationship to Drupal in my blog post from a couple years ago, Solr and Drupal, A History.

Readiness of Search API and Solr for Drupal 8

It's been a few months since Drupal 8.0.0 was released, and we're just beyond the release of 8.1.0. Search API is currently in late alpha stages, Search API Solr is in alpha, and Facets is also in alpha. If you use the latest stable releases of all three modules, you can already start building complex and functional faceted search pages, just like you could in Drupal 7. Over on my personal blog, I posted a tutorial earlier this week describing how to set up a faceted Apache Solr search page on Drupal 8 using these modules, so please have a read through there if you're interested. But, as noted on the Search API module page:

A Drupal 8 version of the module is currently being worked on and already usable, though still some way from stable. If you want to follow (or, even better, help with) development, please see #2044421: [meta] Upgrade to Drupal 8. Join #drupal-search-api on Freenode for helping out. Please also note that, during Alpha phase, there is generally no upgrade path between versions of this module and that any new release might break your site without warning.

So, just like with any other non-stable release (if it has an alpha, beta, or rc in front of it, it's not 'stable'), you will need to be extra vigilant about upgrading the modules... and there's a chance during one of the alpha upgrades you may need to uninstall the module, reinstall it, and then rebuild your search index and search pages. If you'd like to get involved in the efforts towards a stable release, check out this list of Search API beta blockers, and see if there's something you can help fix! If you rely heavily on other related modules for certain functionality (e.g. pretty paths, autocomplete, geolocation field data, etc.), know that few (if any) of those modules are ported to Drupal 8 yet. If your site depends on that deeper search functionality, you will need to either budget time to help get those modules ported and stable, or build some search functionality with custom code at this point (I prefer the former option, since that means everyone in the community wins—including you, for future Drupal projects that require the same modules!). Also, if you want to start testing things today, you can use your Acquia Cloud site—every Acquia Cloud subscription comes with Acquia Search (which uses Solr as a backend, though there are a couple things still being improved for Drupal 8 support)—or you can use Solr built into Drupal VM or as a standalone VM using this Vagrant configuration. Hopefully we'll see even more progress and stability after DrupalCon New Orleans next week!