For a Drupal site that is using Apache Solr we wanted site visitors to be able to widdle down within search results they are browsing. This is typically called Faceted Searching on search platforms. In a previous blog post I wrote about how to configure Apache Solr locally on your network and how to make Drupal aware of Solr through the Search API. In this blog post I’ll specifically be discussing some of the features you can use with Faceted Searches and Solr + Drupal.
Facet Searching and Drupal
When you install the Facet API and Search API module in Drupal it exposes the concept of Facets to Search Indexes. When you define the indexed fields within an Index (a Drupal Content type) each field can contain a Facet. A facet allows a search result query to list related segments of documents regarding the configured field. A facet can be controlled to be AND’ed or OR’ed with other facets; can have custom widget displays (sliders vs text input) and because facets tend to show lots of possible related content and relationships you can control how many options facets show.
Here is an example facet which shows People related to a keyword here. In this project people are the speaker who created the document on this website of presidential documents.
The facets created by the Search API are not directly form widgets to be used in a search form. Rather, they are blocks you can place on a search results page and allow users to facet, or widdle down their search on these faceting fields. A good example of this interface is Amazon.com. On amazon you do a full text search on their products, after an initial search, your shown Categories and a count of Items per Category that relate to your initial search. This is what the Facet API and Search API are generating for you.
Some other examples facets can be seen here:
The above two facets are based off of Drupal taxonomy term fields. This allows a search for “birds” for example to be segmented into only certain types of documents found within the website. This is extremely powerful and flexible.
Some Tips and Roadblocks
You can spend alot of time configuring search fields, related search fields (from linked drupal content) and optimizing this. Your exact Solr + Drupal + Facets implementation will be driven by your requirements.
Additional useful configuration for searching and facets is the Current Search Block module and the Facet API Pretty Paths module.
The current search module shows the currently active facets as items that be partially removed or tweaked by the user. This adds valuable situational awareness of what the user is searching through while they search.
The Facet Prett Paths module takes the default, very ugly, Search API search URL string and changes the parameters into a much more sane URL path.
So what are some gotchas?! One example issue I have found that in my dataset we’re searching through 100,000s of documents spanning from the year 1793 to the present year of 2016. I’d love to be able to facet through or BETWEEEN years of ranges as a custom facet (duh!). But unfortunately the Search API does currently not support the Lucene BETWEEN operator for Dates, nor does the Facet Dates module support this currently — it’s all being worked on (in an issues spanning 3 years).
- https://www.drupal.org/node/1783746 Drupal issue where BETWEEN operator for Solr backend was requested through the Search API.
- https://www.drupal.org/node/1595230 Drupal issue for Date filter using BETWEEN operator with Solr backend.
I hope you’ve found this information helpful! Happy site building!
Looking for quality web hosting? Look no further than Arvixe Web Hosting!