Reputation: 159
in solr i have to get the uniqque values in my 'name' field of my database.
for that reason I read about grouping and Iget the desored esult
{
"responseHeader":{
"status":0,
"QTime":16,
"params":{
"indent":"true",
"q":"name:И*",
"group.field":"name",
"group":"true",
"wt":"json"}},
"grouped":{
"name":{
"matches":2231,
"groups":[{
"groupValue":"ИВАН",
"doclist":{"numFound":1144,"start":0,"docs":[
{
"obshtina":"ПЛОВДИВ",
"phone":"032/670309",
"timestamp":"2013-03-04T08:43:53.553Z"}]
}},
{
"groupValue":"ИЛИЯ",
"doclist":{"numFound":177,"start":0,"docs":[
{
"obshtina":"БРЕЗОВО",
"phone":"(3191)2265",
..............................
ANd I get the the first groupValue
var str = xmlhttp.responseText;
alert (str); //here everything is OK - i get the respone correctly
var rsp = JSON.parse(str);
//var rsp = JSON.parse(xmlhttp.responseText);
var srcAutoComp = new Array();
alert ("grouped:" + rsp.grouped.name.groups[0].groupValue);
But it seems that no matter how much i read I cannot find in the response from solr the number of groups so i can get all the goupvalues in a cicle.
f
Upvotes: 0
Views: 273
Reputation: 52779
You can use group.ngroups to get the total count of groups.
To get all the group values, you can facet on the field keeping a facet limit of -1 which will ensure you get all the unique group values in the response.
Upvotes: 2