3

I want to try new solr collapsing/grouping included in solr 3.3, i have tried queries on solr Admin page and that works absolutely right but when I try to query in my c# code using solr net that does not seem to work as expected. Here is how I am setting the param values

    options.ExtraParams = new List<KeyValuePair<string, string>>
    {
        new KeyValuePair<string,string>("group","true"),
        new KeyValuePair<string,string>("group.field","AuthorID"),
    };
Four
  • 900
  • 1
  • 10
  • 18
Ahsan Iqbal
  • 1,422
  • 5
  • 20
  • 39

1 Answers1

5

Yes, you can use Grouping (formerly known as Field Collapsing) with SolrNet, it was introduced in the SolrNet 0.4.0 alpha1 release. Here are the release notes on the author's blog about this support being added in. So you will need to grab that version (or later) from Google Code(binaries) or GitHub(source). Also here is an example of using grouping from the unit tests in the source - Grouping Tests

public void FieldGrouping()
{
    var solr = ServiceLocator.Current.GetInstance<ISolrBasicOperations<Product>>();
    var results = solr.Query(SolrQuery.All, new QueryOptions
    {
        Grouping = new GroupingParameters()
        {
            Fields = new [] { "manu_exact" },
            Format = GroupingFormat.Grouped,
            Limit = 1,
        }
    });

    Console.WriteLine("Group.Count {0}", results.Grouping.Count);
    Assert.AreEqual(1, results.Grouping.Count);
    Assert.AreEqual(true, results.Grouping.ContainsKey("manu_exact"));
    Assert.GreaterThanOrEqualTo(results.Grouping["manu_exact"].Groups.Count,1);
}
Mauricio Scheffer
  • 98,863
  • 23
  • 192
  • 275
Paige Cook
  • 22,415
  • 3
  • 57
  • 68