4

I have problems with faceting. Imagine this situation. Product can be in more than one category. This is common behavior for faceting:

Category

  • Android (25)
  • iPhone (55)
  • other (25)

Now when I select "Android", I make new query with "fq" => "category:Android", I will get:

Category

  • Android
  • iPhone (15)
  • other (2)

But this means that there is 15 products, that are in categories "Android" AND "iPhone". I would like something like this: ("Android" OR "iPhone")

Category

  • Android
  • iPhone (+5)
  • other (+1)

Meaning I will get 25 results by selecting "Android (25)" and another 5 by selecting "iPhone (+5)", so finally I will get 30 search results..

Does anyone know if this is possible with SOLR's faceting? Or perhaps with more than one query and calculate it manually?

Thanks for advice!

user987220
  • 207
  • 1
  • 2
  • 10
  • By selecting "Android" you get 25 results, where 15 also have the category "iPhone". You wont get 30 results if you add "iPhone". With AND you will get 15 results. If you use OR you will get 25+55 results. Where do the +5 come from? – morja Nov 30 '11 at 17:06
  • "If you use OR you will get 25+55 results" => that would be true if Product could be in just and exactly one category. But in my case it can be in more than one so OR will give me 30 results.. – user987220 Nov 30 '11 at 22:07

2 Answers2

3

Depending on all the permutations you need, you probably want to look into query facets that enable you to get counts for arbitrary queries. For instance, you can do facet.query=category:("Android" OR "iPhone") and get a count results keyed on category:("Android" OR "iPhone"). And, you can do this for any number of queries you want counts for. So, in your case, you can probably get to a final solution with some combination of straight field facets and query facets.

Edit: Re-reading you question, you may also want to look into tagging and excluding parts of an extra fq, depending on how you are allowing your users to "select into" the choices. (The example in the docs is fairly close to your original setup, although I'm not sure the end behavior is exactly as you desire).

Ryan Roemer
  • 987
  • 7
  • 13
  • Thanks for advices, i will definitely look into those, but the answer from nikhil500 is exactly what I was looking for.. – user987220 Nov 30 '11 at 21:48
3

Try a new query with the negative of the selections, like "fq" => "-category:Android" - you should then get the facet counts you are looking for.

nikhil500
  • 3,458
  • 19
  • 23