Mason G. Zhwiti
Mason G. Zhwiti

Reputation: 6530

Multiple facets per field with Solr

By default, Solr returns facets for a field, and then if you select a facet value for that field, all of the other previous choices are no longer returned as part of the facets for that field.

I'm trying to develop a search engine that works more like Amazon's search engine (which is based on their own A9 search engine, and therefore, is probably similar to Amazon CloudSearch).

When you narrow down to some "facets" on Amazon searches, they continue to show the other options, along with the counts if you were to add that area to your search.

Is there a built-in way to do this in Solr? If not, how would I roll my own. Obviously I would need to cache the original facets returned for the field. But what would be the most efficient way to calculate the counts for those other faceted areas once I've already selected one (or more) facets for the field. Obviously when additional facets are selected, you're doing an "OR" query between those values, as you're trying to show things with either of the two values.

For example, I performed a search on Amazon's jewelry department for diamond ring, then narrowed down to Gold as the metal type. I was then able to choose multiple karat facets:

Example Amazon faceting

Can someone provide an example on how I could (efficiently) do this with Solr?

And is there any feature in the works for a future version of Solr that would offer this functionality out of the box (assuming it's not already in the box)?

Upvotes: 4

Views: 10226

Answers (2)

Yonik
Yonik

Reputation: 2381

Multi-select faceting with Solr's new JSON Facet API works a bit differently. You still tag filters the same way, but there is a different exclusion syntax.

&q="running shorts"
&fq={!tag=COLOR}color:(Blue Black)
&json.facet={
      sizes:{type:terms, field:size},
      colors:{type:terms, field:color, domain:{excludeTags:COLOR} },
      brands:{type:terms, field:brand, domain:{excludeTags:BRAND} }
}

Notice tag=COLOR on the filter that is selecting for Blue or Black items. When we facet on color, we want to ignore (or exclude) filters with that tag so we'll still get the other color counts back. That's what the domain:{excludeTags:COLOR} does.

This example was taken from http://yonik.com/multi-select-faceting/

Upvotes: 3

mailboat
mailboat

Reputation: 1077

Tagging and excluding Filters functionality in Solr might be the feature that you are looking for, here is Wiki link explaning Multi Select Faceting.

Ex:: ../solr/select/?q=*&rows=0&facet=on&fq={!tag=krt}KARAT:10k_Gold&facet.field={!ex=krt}KARAT

This feature is present since Solr 1.4 I guess.

Upvotes: 7

Related Questions