I am not yet sure how to expose this in the client API, either via the Lucene query or (heavens forbid) the Linq provider.
Given the following documents:
{"Name":"Oren Eini"}
{"Name":"Oren Eini"}
{"Name":"Ayende Rahien"}
Will result in index: Temp/AllDocs/GroupedByCount
from doc in docs
select new { Count = 1 }
from result in results
group result by new { }
into g
select new
{
Count = g.Sum(x=>x.Count)
}
And the following result:
{
"Results": [
{
"Count": "3"
}
],
"Includes": [
],
"IsStale": false,
"IndexTimestamp": "\/Date(1292760357925)\/",
"TotalResults": 1,
"SkippedResults": 0,
"IndexEtag": "00000000-0000-1500-0000-00000000000b"
}
While this:
Resulted in the following Temp/AllDocs/ByName/GroupedByCount:
from doc in docs
select new { Name = doc.Name, Count = 1 }
from result in results
group result by result.Name
into g
select new
{
Name = g.Key,
Count = g.Sum(x=>x.Count)
}
{
"Results": [
{
"Count": "1",
"Name": "Ayende Rahien"
},
{
"Count": "2",
"Name": "Oren Eini"
}
],
"Includes": [
],
"IsStale": false,
"IndexTimestamp": "\/Date(1292760357925)\/",
"TotalResults": 2,
"SkippedResults": 0,
"IndexEtag": "00000000-0000-1500-0000-00000000000b"
}
Which used the same index as before, but generates just:
{
"Results": [
{
"Count": "2",
"Name": "Oren Eini"
}
],
"Includes": [
],
"IsStale": false,
"IndexTimestamp": "\/Date(1292760357925)\/",
"TotalResults": 1,
"SkippedResults": 0,
"IndexEtag": "00000000-0000-1500-0000-00000000000b"
}