Example Solr Faceted Search blocks

David G - DrupalFor 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.

This facet is an example of related people how have mentioned "bird" in their speeches or documents.

This facet is an example of related people how have mentioned “bird” in their speeches or 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:

Example facets for a document which use Taxonomy terms.

Example facets for a document which use Taxonomy terms.

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.

By selecting facet items on the search page the existing search is refined. These conditions become removable options in the current search block at the top of the page. The faceting has a Stack effect for searching.

By selecting facet items on the search page the existing search is refined. These conditions become removable options in the current search block at the top of the page. The faceting has a Stack effect for searching.

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.

Example before and after image of pretty facet urls from the Facet Pretty Path project page.

Example before and after image of pretty facet urls from the Facet Pretty Path project page.

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).

I hope you’ve found this information helpful! Happy site building!

Looking for quality web hosting? Look no further than Arvixe Web Hosting!

Tags: , , , , | Posted under Drupal | RSS 2.0

Author Spotlight

David Gurba

I am a web programmer currently employed at UCSB. I have been developing web applications professionally for 8+ years now. For the last 5 years I’ve been actively developing websites primarily in PHP using Drupal. I have experience using LAMP and developing data driven websites for clients in aviation, higher education and e-commerce. If you’d like to contact me I can be reached at david.gurba@arvixe.com

Leave a Reply

Your email address will not be published. Required fields are marked *