2

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

javanna
  • 59,145
  • 14
  • 144
  • 125
randika
  • 1,519
  • 3
  • 18
  • 39
  • so does grouping affect results or is that only for display? (i.e. just show the groups that Solr returns) – Mauricio Scheffer May 01 '11 at 16:53
  • 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 May 01 '11 at 18:18
  • what I'm asking is: do you need to group results throughout the whole index? or just within a single result page? – Mauricio Scheffer May 01 '11 at 18:24
  • yes I need to group it throughout the index. – randika May 01 '11 at 19:09

1 Answers1

0

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.

Mauricio Scheffer
  • 98,863
  • 23
  • 192
  • 275
  • Ok it seems like SoltNet's grouping option is not available on the trunk, but still its available on solr's nighly builds. -- anyway you were asked whether I need this to work through out the index or only for display? Do you think Is there anyway I can group them from display level. Thank you. – randika May 03 '11 at 07:38
  • @randika: if you want to group throughout the whole index you need server-side support (from Solr and SolrNet). If you only want to group in a single result page you can do it easily with LINQ. – Mauricio Scheffer May 03 '11 at 12:53
  • Hi Mauricio, Since field collapsing is not available as a stable release of Solr we decided not to use it, instead we decided to index `groups` also on the same index. So when we search now we can list both the products and group names. So it's working. But still we couldn't show the group names on the top of the results. – randika May 07 '11 at 09:27
  • So far the coding looks like this: `var options = new QueryOptions(); options.FilterQueries = BuildFilterQueries(parameters); options.FilterQueries.Add(Query.Field("has_group").Is(false)); options.OrderBy.Add(new SortOrder("group_name", Order.ASC)); ` – randika May 07 '11 at 09:33