作者:隔壁老吴 | 来源:互联网 | 2023-05-19 03:35
1、要实现的功能
5、solrJ实现
public List getTypeTree(Integer type,String name) throws SolrServerException{
SolrServer solrServer = SolrServerManger.getInstance();
SolrQuery sQuery = new SolrQuery();
List types=new ArrayList();
sQuery.setFacet(true);
sQuery.add("facet.pivot", "p_type_name,type_name"); //根据这两维度来分组查询
switch (type) {
case 1:
sQuery.setQuery("name:"+name);
break;
case 2:
sQuery.setQuery("shop_id:"+name);
break;
default:
sQuery.setQuery("*:*");
break;
}
QueryResponse respOnse= solrServer.query(sQuery);
NamedList> namedList = response.getFacetPivot();
if(namedList != null){
List pivotList = null;
for(int i=0;i fieldList = pivot.getPivot();
if(fieldList != null){
List typeThrees=new ArrayList();
for(PivotField field:fieldList){
SearchType typeThree=new SearchType();
typeThree.setName(field.getValue().toString());
typeThrees.add(typeThree);
}
typeTwo.setSubTypes(typeThrees);
types.add(typeTwo);
}
}
}
}
}
return types;
}
6、solrj测试代码
public static void main(String [] args) throws SolrServerException{
List types=getTypeTree(2, "123");
for(SearchType t:types){
System.err.println(t.getName()+"===========");
for(SearchType tt:t.getSubTypes()){
System.err.println(" ---"+tt.getName());
}
}
}
7、测试结果