Here is an example how to use the pivot tables feature within Solr using SolrNet.
To use it download the current source code of SolrNet from github. (select the master branch)
var url = "someurlwhereyoursolrisrunning";
Startup.Init<Model.doc>(url);
var solr = ServiceLocator.Current.GetInstance();
//Create a facet Pivot Query
var facetPivotQuery = new SolrFacetPivotQuery()
{
//Define 2 pivots, one for inStock subgrouped by cat and
//one for manu_exact subgrouped by cat
Fields = new[] {
"inStock,cat",
"manu_exact,cat"
},
//Set the minCount to 1
MinCount = 1
};
//Create the facet parameters
//Note that you can use pivotQueries together
//with other facets queries
var facetParams = new FacetParameters()
{
Queries = new[] { facetPivotQuery },
//Limit the amounts of pivotRows to 15
Limit = 15
};
var queryOptions = new QueryOptions();
queryOptions.Facet = facetParams;
queryOptions.Rows = 0;
var results = solr.Query("ipod", queryOptions);
if (results.FacetPivots.Count > 0)
{
foreach (var pivotTable in results.FacetPivots)
{
Console.WriteLine(String.Format("Pivot {0}, has {1} childgroups",
pivotTable.Key,
pivotTable.Value.Count.ToString()));
}
}
1 comment:
Hi Klaas, would you be interested in contributing some documentation to SolrNet?
Cheers,
Mauricio
Post a Comment