I have a comma separated field value called 'Categories' which I have indexed & stored using a custom field type defined as:
<fieldType name="text_comma_delimited" class="solr.TextField">
<analyzer>
<tokenizer class="solr.PatternTokenizerFactory" pattern="," />
</analyzer>
</fieldType>
and I defined the field as:
<field name="Categories" type="text_comma_delimited" indexed="true" stored="true" />
Now I want products grouped by these categories so I use a simple grouping query like this:
http://localhost:8089/solr/products/select?q=*:*&wt=json&indent=true&group=true&group.field=Categories&group.limit=-1&rows=-1&group.ngroups=true&group.facet=true
But the result that I get just gives back 2 groups instead of 6. It seems that it is considering one-one relationship between product and category hence one product is appearing only once where as it should be a one to many. One product can appear in more than one categories. Here is the result:
{
"responseHeader":{
"status":0,
"QTime":2,
"params":{
"fl":"Category,SKU",
"group.ngroups":"true",
"indent":"true",
"start":"0",
"q":"*:*",
"group.limit":"-1",
"group.field":"Category",
"group":"true",
"wt":"json",
"group.facet":"true",
"rows":"-1"}},
"grouped":{
"Specialties":{
"matches":6,
"ngroups":2,
"groups":[{
"groupValue":"Fiction",
"doclist":{"numFound":3,"start":0,"docs":[
{
"SKU":"F5678",
"Category":"Fiction,ABC,XYZ"},
{
"SKU":"F9876",
"Category":"Fiction,ABC,PQR"},
{
"SKU":"F2365",
"Category":"PQR,Fiction"},
]},
{
"groupValue":"Technical",
"doclist":{"numFound":1,"start":0,"docs":[
{
"SKU":"T9876",
"Category":"CVB,Technical"}]
}}]}}}
I tried the faceting and it clearly shows the correct count for each category with this url:
http://localhost:8089/solr/products/select?q=*:*&wt=json&indent=true&facet=true&facet.field=Categories
The result gives me the perfect list and count, but the above grouping response just falls short of data:
"facet_counts":{
"facet_queries":{},
"facet_fields":{
"Categories":[
"Fiction",3,
"Mystery",1,
"Sci-Fi",1,
"Self Help",1,
"Technical",1,
"Philosophy",1
]},
"facet_dates":{},
"facet_ranges":{}}}
Also, the 'Load Term Info' in the schema browser of the solr admin console shows the above field values and count. It is just that the group query is not returning correctly. Anything else that can be tried for this? Any help is appreciated.