solr 之多维度分组查询facet.pivot

参看 :http://blog.csdn.net/a925907195/article/details/42241265

主要是获取的结果处理逻辑这段

sQuery.add("facet.pivot", "newsType,property");//根据这两维度来分组查询
                sQuery.setQuery(para);
            QueryResponse response = solrServer.query(sQuery,SolrRequest.METHOD.POST);     
            NamedList<List<PivotField>> namedList = response.getFacetPivot();
            System.out.println(namedList);//底下为啥要这样判断,把这个值打印出来,你就明白了
            if(namedList != null){
                List<PivotField> pivotList = null;
                for(int i=0;i<namedList.size();i++){
                    pivotList = namedList.getVal(i);
                    if(pivotList != null){
                        ReportNewsTypeDTO dto = null;
                        for(PivotField pivot:pivotList){
                            dto = new ReportNewsTypeDTO();
                            dto.setNewsTypeId((Integer)pivot.getValue());
                            dto.setNewsTypeName(News.newsTypeMap.get((Integer)pivot.getValue()));
                            int pos = 0;
                            int neg = 0;
                            List<PivotField> fieldList = pivot.getPivot();
                            if(fieldList != null){
                                for(PivotField field:fieldList){
                                    int proValue = (Integer) field.getValue();
                                    int count = field.getCount();
                                    if(proValue == 1){
                                        pos = count;
                                    }else{
                                        neg = count;
                                    }
                                }
                            }
                            dto.setPositiveCount(pos);
                            dto.setNegativeCount(neg);
                            list.add(dto);
                        }
                    }
                }
            }

            return list;

猜你喜欢

转载自blog.csdn.net/u013045102/article/details/79619596
今日推荐