I have a specific query with SOLR that I cannot seem to find a solution for. I have an index full of products and sku's. A product has multiple sku's and every sku has 1 product. I want to perform a search against my SKU's only, group by the parent product and return just the details of the parent product (but not the details of the items).But, I want the facets to represent the original list of items. Is this possible with SOLR today? and what version is this available at?
2 Answers
I think it is possible, my suggestion is to design your core so that the document represent only one SKU, or one item. So, your Unique Id will be the SKU Id. Then you need a productId that is not unique and could have the same value for SKUs that have the same parent product.
You can also de-normalize product details across all documents. So, when you return the details of the item, you also have the details of the produce with it.
The trick here on the query is to use grouping, or field collapsing feature in Solr. See more details here: https://wiki.apache.org/solr/FieldCollapsing
But as a start I suggest setting these values in the query:
- Set
group=true
(this will enable grouping) - Set
group.field=productId
(to group, or collapse items by productId) - Set
group.facet=false
(to include details of all items in facet counts)
So, this will enable you to search across all items, return results grouped by ProductId, and facet numbers will be applied to all items. This is not a new feature, if you have any Solr 3.3, or 4.x you should be able to use grouping.