zoukankan      html  css  js  c++  java
  • Solr的学习使用之(八)facet实战

    以下为统计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;    
        }
  • 相关阅读:
    Mongodb_文件存储
    Mongodb_技巧
    Blend_Effect
    WPF_界面_图片/界面/文字模糊解决之道整理
    ASP.NET Boilerplate 深入系列之:概述
    P1280 尼克的任务
    P1802 5倍经验日
    271. 杨老师的照相排列
    P1726 上白泽慧音
    P1983 [NOIP2013 普及组] 车站分级
  • 原文地址:https://www.cnblogs.com/ontheroad_lee/p/3526375.html
Copyright © 2011-2022 走看看