您的位置:首页 > 其它

Solr的学习使用之(八)facet实战

2014-01-19 23:59 441 查看
以下为统计media的数量功能,通过solrj,采用了facet方法,类似于sql的分组group by查询;这边的代码只是获取总媒体数量,其实他还有其他功能,去循环solrList的话,可以获取各个媒体的数量

public int getMediaCount(Keyword keyword) {
HttpSolrServer solrServer = SolrServer.getInstance().getServer();
SolrQuery sQuery = new SolrQuery();
int result = 0;
try {
String para = this.initKeywordQueryPara(keyword);//这边的值大概是酱紫的 "* AND publishTime:[1360000 TO 13700000]  AND contentStr:\"关键字\"";
sQuery.setFacet(true);
sQuery.setFacetMinCount(1);
sQuery.addFacetField("channelName");
sQuery.setQuery(para);
QueryResponse response = solrServer.query(sQuery,SolrRequest.METHOD.POST);
List<Count> solrList = response.getFacetField("channelName").getValues();
result = solrList.size();
return result;
} catch (SolrServerException e) {
log.error("查询solr失败", e);
e.printStackTrace();
} finally{
solrServer.shutdown();
solrServer = null;
}

return result;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: