I have a solr query like this
q=categories:cat1 OR categories:cat2&stats=true&stats.field=count&stats.facet=block_num
Basically, I want to get the sum(count) group by block num.
This query works on a browser. But with solrj, I could not access the stats fields from Response obj. I can do a response.getFieldStatsInfo(). But it is not what I want. Here is how I construct the query
SolrQuery query = new SolrQuery(q);
query.add("stats", "true");
query.add("stats.field", "count");
query.add("stats.facet", "block_num");
With a debugger, I could see that the response has a private statsInfo object and it has the information I am looking for. But there is no api to access the object.
I would like to know if there is
Thanks!
It is possible to do something like this:
// Field names
private static final String FIELD_ONE = "field_one";
private static final String FIELD_TWO = "field_two";
// Initialized somewhere in constructor
private final HttpSolrServer solrClient;
public void printStats() throws SolrServerException {
final SolrQuery query = new SolrQuery("*:*");
query.setGetFieldStatistics(true);
query.setGetFieldStatistics(FIELD_ONE);
query.setGetFieldStatistics(FIELD_TWO);
final QueryResponse response = solrClient.query(query);
final FieldStatsInfo fieldOneStats = response.getFieldStatsInfo().get(FIELD_ONE);
System.out.println(fieldOneStats.getSum());
System.out.println(fieldOneStats.getMin());
System.out.println(fieldOneStats.getMax());
final FieldStatsInfo fieldTwoStats = response.getFieldStatsInfo().get(FIELD_TWO);
System.out.println(fieldTwoStats.getSum());
System.out.println(fieldTwoStats.getMin());
System.out.println(fieldTwoStats.getMax());
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With