Faceted Search on Input

So one trick with Sphinx search is faceted search. It’s somewhat crudely implemented, by batching queries together, but does the job well. In the case of Firefox Input it can reduce quite a bit of queries (our search result pages take one batched sphinx query, and one database query now instead of 5 database queries).

Faceted search is search with filters to help narrow down a result set. I’ll give you three examples. Firefox Add-ons which I wrote, Sitter City which gives you a lot of ways on narrowing down on the perfect baby sitter and ebay which lets your narrow down on auction items.

For Input we ask for the following when we do a search:

  • How many opinions match the term for which we are searching taking into account any preferences we have already specified (feeling, locale, operating system, date range, etc).
  • How many opinions show a positive sentiment, and how many show a negative sentiment?
  • What is the breakdown of languages for the opinion results. (I.e. how many are en-US, de, fr, etc).
  • How many people are on Mac, Linux or Windows.

We can batch these four queries into a single Sphinx request.

Here’s our implementation.

Having done this twice, I do recognize that there is a lot of room for making the code a bit more reusable. But overall it runs fairly well.