Graphics using SolrJ and Solr4

I reviewed related issues on this site, but did not find an appropriate solution.

When querying my Solr4 index using an HTTP form request

&facet=true&facet.field=country

The response contains all the different countries along with accounts for each country.

How can I get this information using SolrJ? I tried the following, but it only returns totals for all countries, not for the country:

solrQuery.setFacet(true);
solrQuery.addFacetField("country");

The following seems to work, but I don't want to explicitly list all groups in advance:

solrQuery.addFacetQuery("country:usa");
solrQuery.addFacetQuery("country:canada");

Secondly, I'm not sure how to extract facet data from a QueryResponse object.

So, two questions:

1) Using SolrJ, how can I draw on the field and return groups without explicitly specifying groups?

2) Using SolrJ, how can I extract facet data from a QueryResponse object?

Thank.

Update:

().

List<FacetField> ffList = resp.getFacetFields();
log.info("size of ffList:" + ffList.size());
for(FacetField ff : ffList){
    String ffname = ff.getName();
    int ffcount = ff.getValueCount();
    log.info("ffname:" + ffname + "|ffcount:" + ffcount);           
}

ffList = 1, 1 . ffname = "country" ffcount - , .

.

, solrQuery addField addFilterQuery. , :

solrQuery.addField("user-name");
solrQuery.addField("user-bio");
solrQuery.addField("country");
solrQuery.addFilterQuery("user-bio:" + "(Apple OR Google OR Facebook)");

2:

, , , . List, FacetField.getValues ​​().

List<FacetField> fflist = resp.getFacetFields();
for(FacetField ff : fflist){
    String ffname = ff.getName();
    int ffcount = ff.getValueCount();
    List<Count> counts = ff.getValues();
    for(Count c : counts){
        String facetLabel = c.getName();
        long facetCount = c.getCount();
    }
}

, - .

+5
2

, ( SolrJ):

solrQuery.addFacetField("country");

? QueryResponse.getFacetFields (getValues.getCount)

+7

solr Response QueryResponse.getFacetFields(), List of FacetFields, "". "" idenditfied QueryResponse.getFacetFields().get(0)

, List Count,

QueryResponse.getFacetFields().get(0).getValues().get(i)

QueryResponse.getFacetFields().get(0).getValues().get(i).getName()

QueryResponse.getFacetFields().get(0).getValues().get(i).getCount()
+1

All Articles