Monday, 13 March, 2017 UTC


Summary

Facets are a key feature for a search engine. A facet is a way to filter the data by a specific value on an attribute – a good example of a facet is “brands” in an ecommerce website. With Algolia, each set of results for a search query contains the most common occurrences for each facet. This means if you have many values, some will be hidden. The simple solution to this problem, is to fetch more values, but it may not be enough and the user would need to look for the value manually. Our previous solution for this problem was to recommend developers create a new index for each facet they wanted to make searchable – this was a lot of work to build and maintain manually.
Digging further into the e-commerce example, let’s say you’re looking for a new pair of khaki pants from your favorite indie brand. If the brand isn’t well known, then even if you know that a store carries this brand, it may not appear in the first results or even in the list of brands among the facets if it’s not in the top ten brands of this site. You would have to filter other parameters in order for the results to be more focussed on the brand you want. And that’s only if you are persistent, because we all know that googling the website name & the name of the brand will give you some results – that’s where search for facet values comes in. It lets you filter the brands in order to find the one you want, from the very beginning of the search.
We’re thrilled to announce today search for facet values, a new feature to give end-users full control to explore and actually use those hidden values, enabling you to deliver on your promise to connect your users with what matters most to them.
A very popular example: LinkedIn
A very  popular usage of this feature comes from LinkedIn (not an Algolia customer today). The use-case here makes a lot of sense: filtering people by the company they worked at or currently work for makes the number of potential companies huge. If you’re looking for a special skill-set from a company, you want a specific company, and only seeing 5 companies (usually the same 5 largest companies) makes it very unlikely that you’ll see in the list the one you want – so you search within those facets.
Let’s dig into Linkedin’s search experience. In the advanced search, there is a panel containing multiple refinement lists – company, location, industries & more. At the end of each list, there is an add button that triggers the feature.
The user is then presented with an input, which is actually a dropdown. This lets the user search for values inside this category. This search is done on all the values available for that facet.
Searching within these values is particularly useful because a lot of them may exist and the order they come back from the server is based on the number of occurrences. In this example, this is particularly true because there are a lot of companies and they are very likely to have a similar number of occurrences so it’s hard to say that the first n are really better than the next n facet values.
Behind the scenes
Until now, implementing this feature meant extra work preprocessing the data. For each faceted attribute, you had to build a dedicated index with the occurrences of the elements. This index had to be kept up to date, as records were added, deleted or updated.
But not anymore! It only requires two elements:
  • Configure the facet to be searchable: searchable(attribute) instead of attribute in the attributesForFacetting
  • Use the new method of the API to actually search in the values
This new feature added to our API is available in all our API clients using the method called searchForFacetValues(), as well as in the JS Helper. That method accepts a specific query to specify the search and the whole set of filters that you can send to index queries. This allows the search for facet values to be contextualized.  This filters the values to only those that make sense for the current query.
For example, in an ecommerce website for which we have two faceted attributes: type of good and color. If you search for “apples”, you don’t want purple to be proposed because there are no purple apples (not that I know of, at least).

Baked in our widgets

A feature is only as valid as its ease-of-use. Since we provide an end-to-end developer experience from the REST API to the UI, we wanted to implement the searchable refinement list right in our widget libraries instantseach.js and react-instantsearch.
When I first I looked at the LinkedIn implementation, something didn’t seem quite right. It felt as if the feature was hidden from the users and the space could be used more efficiently. We prototyped two versions of the search refinement list and we ended up with two simple implementations that we tested internally:
 
We then conducted a study with those two prototypes and it turned out that for us, the second version was the best. It was especially true for those who had no prior knowledge of the LinkedIn implementation.
This implementation is now available to you directly in instantsearch.js and in react-instantsearch. It is not a new widget but just a new option to pass to the refinement list which will transform the list into a search one.

See it in action: redoing TED search

To demonstrate this new feature we built a brand new demo based on TED talks. In this search, we have set filters based on events, the kind of conference (original, TEDx, and so on), topics and languages. Each of those filters contains more entries than we can display which makes them perfect for this using search for facet values.
Try it out!

Going beyond with search for facet values

Search for facet values is a great feature and with our current implementation baked into instantsearch libraries (vanilla js or react) we take advantage of it with few tweaks. But the truth is that we are only scratching the surface. This feature actually opens us to implementations like smart search bars like Slack that let the user refine facets within the search-box.
If you’re wondering how to get started, we’ve updated our guides (because we <3 guides):
  • Learn how to use this new feature in our Instantsearch result page guide
  • And more in detail in the Filtering and faceting guide
Let us know what cool things you’ve built in the Algolia community forum.