玩龙天子 发表于 2017-12-19 09:59:56

7.solr学习速成之facet

package>import java.io.IOException;import java.util.ArrayList;import java.util.List;import org.apache.solr.client.solrj.SolrQuery;import org.apache.solr.client.solrj.SolrServerException;import org.apache.solr.client.solrj.impl.HttpSolrClient;import org.apache.solr.client.solrj.response.FacetField;import org.apache.solr.client.solrj.response.FacetField.Count;import org.apache.solr.client.solrj.response.QueryResponse;public>public static void addIndex(){  HttpSolrClient server
= solrServer.getServer();  List
<ProductBO> list = new ArrayList<>();  ProductBO bo1
= new ProductBO();  bo1.setId(
"1001");  bo1.setTitle(
"27寸曲面显示器");  bo1.setMajor_s(
"电器");  bo1.setSubMajor_s(
"显示器");  bo1.setBrand_s(
"海尔儿");  bo1.setPrice_i(
5000);  list.add(bo1);
  bo1
= new ProductBO();  bo1.setId(
"1002");  bo1.setTitle(
"无敌28寸曲面显示器");  bo1.setMajor_s(
"无敌电器");  bo1.setSubMajor_s(
"无敌显示器");  bo1.setBrand_s(
"无敌海尔儿");  bo1.setPrice_i(
6000);  list.add(bo1);
  bo1
= new ProductBO();  bo1.setId(
"1003");  bo1.setTitle(
"超级28寸曲面显示器");  bo1.setMajor_s(
"超级电器");  bo1.setSubMajor_s(
"超级显示器");  bo1.setBrand_s(
"超级海尔儿");  bo1.setPrice_i(
7000);  list.add(bo1);
  bo1
= new ProductBO();  bo1.setId(
"1004");  bo1.setTitle(
"28寸曲面显示器");  bo1.setMajor_s(
"电器");  bo1.setSubMajor_s(
"显示器");  bo1.setBrand_s(
"海尔儿");  bo1.setPrice_i(
7000);  list.add(bo1);
try {  server.addBeans(list);
  server.commit();
  }
catch (SolrServerException | IOException e) {  e.printStackTrace();
  }
  }
public static void>HttpSolrClient server = solrServer.getServer();  SolrQuery query
= new SolrQuery();  String para
= "*:*";  query.setFacet(
true);  query.addFacetField(
new String[]{"subMajor_s","brand_s"});  query.setFacetLimit(
100);//限制facet返回数量  query.setFacetMissing(false);//不统计null的值
  query.setFacetMinCount(1);//分组的数据最小为1
  query.addFacetQuery("price_i:");
  query.setQuery(para);
  QueryResponse queryResponse;
页: [1]
查看完整版本: 7.solr学习速成之facet