2
votes

I'm using Solr for a product catalogue built on asp.net with solrnet and everything works pretty well so far. I need to extend the search results by adding some grouping option to it.

First I’ll explain how the schema looks like:

 <field name="product_id" type="string" indexed="true" stored="true" required="true" /> 
 <field name="name" type="string" indexed="true" stored="true"/>
 <field name="merchant" type="string" indexed="true" stored="true"/>
 <field name="merchant_id" type="int" indexed="false" stored="true"/>
 <field name="merchant_logo" type="string" indexed="false" stored="true"/>
 <field name="brand" type="string" indexed="true" stored="true"/>
 <field name="brand_id" type="int" indexed="false" stored="true"/>
 <field name="group_id" type="int" indexed="true" stored="true"/>
 <field name="group_name" type="string" indexed="true" stored="true"/>
 <field name="has_group" type="boolean" indexed="true" stored="true"/>

So as you see products above has a “group_id” and “group name” also I have Boolean flag named “has group” on my schema.

Here are some examples of products results

Product A – group id 1 - group Name 1 – has group true
Product B – group id 1 - group Name 1 – has group true
Product C – group id 2 - group Name 2 – has group true
Product D – group id 2 - group Name 2 – has group true
Product E – has group false
Product F – has group false

But when I’m showing these results, I need to show the products with group names (or ids) on top the results by Its group name. And the products which doesn’t belongs to a group will be listed on right after the groups.

So my results should looks like:

Group Name 1
Group Name 2
Product E
Product F

Indeed I need to implement the pagination as well, so in other words when someone search for some product if a the products contains group names I’ll list them on top of the results and next the other products.

Is this even possible? If it is possible, what would I need to do. I already read about FieldCollapsing in solr but still I have no idea whether this is the right way or not http://wiki.apache.org/solr/FieldCollapsing

1
so does grouping affect results or is that only for display? (i.e. just show the groups that Solr returns) - Mauricio Scheffer
Well the way it works currently when search for products currenly I get mixture of products which has group data and also product without group data. Basically when I print product result I need product group names (ONLY GROUP NAME) to be printed first and then the other products. Is Solr itself has a support for grouping solr results? becuase I need to use the pagination for the results as well as faceting too. So may be what I'm looking for is a Solr query for grouping. - randika
what I'm asking is: do you need to group results throughout the whole index? or just within a single result page? - Mauricio Scheffer
yes I need to group it throughout the index. - randika

1 Answers

0
votes

Yes, if you want grouping over the whole index you need the field collapsing feature. SolrNet's support for this is currently broken, since it's an unreleased feature in Solr and changed a lot since the first implementation in SolrNet. See http://code.google.com/p/solrnet/issues/detail?id=127 for details and updates.