Search Options in Drupal 7

There are currently three options for search in Drupal 7:  default site search, Apache Solr, and ElasticSearch.  In Drupal 7, ElasticSearch is not built out sufficiently to really be a viable option.  Default site search does not offer much of a level of flexibility, so that leaves us with Apache Solr as the best option for search in Drupal 7.

There are 2 approaches to implementing Apache Solr in Drupal 7: via the Apache Solr and related modules and via the Search API module.   The determination as to which implementation to use may depend on the website environment.  For example, ILAO is hosted on Acquia Cloud and currently uses their Acquia search product.  Acquia recommends using Apache Solr for Drupal 7 and Search API only for Drupal 8.  For websites that run using any other Solr instance, the Search API is likely a better option.

Apache Solr module approach

The Apache Solr approach will require configuration and inclusion of a number of modules, depending on the website’s configuration.  Some modules that may need to be used:

  • The Apache Solr module provides the bulk of the configuration options.  Drupal sites can use either the Apache Solr module OR the Search API module but not both.  
  • The Apache Solr Exclude module allows us to exclude nodes from the search index on a per-node basis.  It adds a field to each node where we can mark “yes, exclude from search” where needed on content types where we have implemented it.
  • Apache Solr Views - allows for Views integration with search results.  This allows for more flexible layouts than using the default search results page that ship with Apache Solr.
  • The Apache Solr multilingual module adds support for multilingual websites.  
  • The Apache Solr paragraphs module is needed for any use of the Paragraphs module.  ILAO for example makes extensive use of paragraphs.
  • The FacetAPI module allow websites to add filters/facets to searches for most fields in their content.  Facets can be restricted by roles (for example, allowing only advocate users to filter by last updated date) and by bundle attached to (for example, allowing searches on legal issue only for legal content and not for events).
  • Apache Solr Views module allows for more flexible layouts and integration with Drupal’s Views module to offer a superior user experience than the default search results page that Apache Solr module offers.
  • The Search Autocomplete module allows us to include an autocomplete feature in our search bar.  However, it lacks good multilingual support

Search API Approach

Using the search api approach can leverage the following:

  • Search API module, which contains really three modules:
    • Search API
    • Search API Facet - like the FacetAPI module, allows for the creation of facets to filter search information on.
    • Search API views - like the Apache Solr Views module, exposes search information to the Views module.  This allows for more flexible layouts to offer a superior user experience than the default search results page that Drupal provides.
  • Search API Solr which allows one to connect to a Solr search engine.
  • Search API autocomplete to provide autocomplete suggestions.  This is an alternative module to the Search autocomplete module for Apache solr.

Both the Search API module and the Apache Solr modules include similar APIs to interact with Solr.  These APIs include functions to  

  • Altering a search query before it is executed in Solr.  Example uses:
    • if a user searches for “divorce”, perhaps I run it through a function that gives extra weight when the title contains the word divorce or adds an extra search keyword for dissolution of marriage from a thesaurus
    • If a user is not logged in, and an access field exists on a node, a query alter would allow returning only unrestricted content.
  • Altering results.  Example uses:
    • Strip out bad text.  For example, the ratings module adds “Add rating” to all of ILAO’s search results.
    • Replace text.  For example, in place of a snippet, perhaps the content description would be better for some types of content

The Search API also includes a robust API library to control what is and what is not included in the search index, while the Apache Solr module allows configuration of this information primarily through a user interface

The Apache Solr API also allows for customizing recommended “Did you mean “ suggestions.

 

This research was funded by a Legal Services Corporation Technology Initiative Grant (TIG) and compiled in June 2018 by Illinois Legal Aid Online and Pine Tree Legal Assistance.

 

 

Posted: June 25, 2018