My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
Stats  
Updated Apr 6, 2011 by mauricio...@gmail.com

Stats

This feature provides you with simple statistics for numeric fields within the query results:

MinThe minimum value
MaxThe maximum value
SumSum of all values
CountHow many (non-null) values
MissingHow many null values
SumOfSquaresSum of all values squared (useful for stddev)
MeanThe average (v1+v2...+vN)/N
StdDevStandard Deviation -- measuring how widely spread the values in a data set are.

Sample usage:

ISolrOperations<Product> solr = ...
var results = solr.Query(SolrQuery.All, new QueryOptions {
    Rows = 0,
    Stats = new StatsParameters {
        Facets = new[] { "inStock" },
        FieldsWithFacets = new Dictionary<string, ICollection<string>> {
            {"popularity", new List<string> {"price"}}
        }
    }
});

foreach (var kv in results.Stats) {
    Console.WriteLine("Field {0}: ", kv.Key);
    var s = kv.Value;
    Console.WriteLine("Min: {0}", s.Min);
    Console.WriteLine("Max: {0}", s.Max);
    Console.WriteLine("Sum of squares: {0}", s.SumOfSquares);
    foreach (var f in s.FacetResults) {
        Console.WriteLine("Facet: {0}", f.Key);
        foreach (var fv in f.Value) {
            Console.WriteLine("Facet value: {0}", fv.Key);
	    Console.WriteLine("Min: {0}", fv.Value.Min);
	    Console.WriteLine("Max: {0}", fv.Value.Max);
	    Console.WriteLine("Sum of squares: {0}", fv.Value.SumOfSquares);
        }
    }
}

For more details see the Solr wiki.

Powered by Google Project Hosting