This section describes how to query SOLR groups:
Public static Map <string, integer> querybygroup (string qstr, string groupfield, string sortfield, Boolean ASC, integer pagesize, integer pagenum ){
Map <string, integer> RMAP = new linkedhashmap <string, integer> ();
Try {
Solrserver Server = getsolrserver (); // The getsolrserver () method returns a commonshttpsolrserver
Solrquery query = new solrquery ();
If (qstr! = NULL & qstr. Length ()> 0)
Query. setquery (qstr );
Else
Query. setquery ("*: *"); // if no query statement exists, it must be written in this way. Otherwise, an exception is reported.
Query. setshortdescore (false); // determines whether to sort by the number of groups.
Query. setfacet (true); // whether to query by group
Query. setrows (0); // you can specify the number of returned results. If you query results by group, set the value to 0.
Query. addfacetfield (groupfield); // Add a group field
Query. setfacetsort (true); // whether the group is sorted
Query. setfacetlimit (pagesize); // limit the number of results returned each time
Query. setsortfield (sortfield, ASC? Solrquery. Order. ASC: solrquery. Order. DESC); // group sorting Field
Query. Set (facetparams. facet_offset, (pageNum-1) * pagesize); // the starting position of the current result
Queryresponse RSp = server. Query (query );
List <count> countlist = RSP. getfacetfield (groupfield). getvalues ();
List <count> returnlist = new arraylist <count> ();
If (pagenum * pagesize <countlist. Size ())
Returnlist = countlist. sublist (pageNum-1) * pagesize, pagenum * pagesize );
Else
Returnlist = countlist. sublist (pageNum-1) * pagesize, countlist. Size ()-1 );
For (count: returnlist ){
If (count. getcount ()> 0)
RMAP. Put (count. getname (), (INT) count. getcount ());
}
} Catch (exception e ){
E. printstacktrace ();
}
Return RMAP;
}