I am pretty new to faceted search, so it is kind of difficult for me to wrap my head around this... but here goes:
Pretend I have Item
which contains a collection of SubItem
s and the SubItem
has an enum that indicates a status - I have successfully enabled faceted search on categories on both Item
and SubItem
using this index definition:
public class FacetIndexItems : AbstractIndexCreationTask<Item>
{
public const string FacetId = "facets/Items";
public const string ItemCategoryFacetName = "Category";
public const string SubItemCategoryFacetName = "SubItems_Category";
public FacetIndexItems()
{
Map = items => from item in items
from subItem in item.SubItems
select new
{
Category = item.Category,
SubItems_Category = subItem.Category
};
}
}
and this FacetSetup
:
new FacetSetup
{
Id = FacetIndexItems.FacetId,
Facets =
{
new Facet {Name = FacetIndexItems.ItemCategoryFacetName},
new Facet {Name = FacetIndexItems.SubItemCategoryFacetName}
}
}
So far, so good!
Now, pretend that SubItem
has a Status
property - is there a way to divide the result of each facet into different statuses?
E.g. so that quering this data:
{
Category: "wut",
SubItems: [
{Category: "bim", Status: "good"},
{Category: "bim", Status: "good"},
{Category: "bim", Status: "bad"}
]
}
by item.Category.In("wut") && item.SubItems.Any(s => s.Category.In("bim"))
would yield a result like
{
Category: {
"good": 2
"bad": 1
},
SubItems_Category: {
"good": 2
"bad": 1
}
}
I am unsure whether this is actually possible to do with faceted search, and I am definitely open to alternatives if my approach is wrong.
You would have to generate different values for each option, you can't do a facet on more than one field at a time. But you can generate fields at indexing time, so that does the same thing.