solr多条件查询

solr多条件查询
bug:今天solr多条件查询,过滤后,同种数据类型处理最后一个字段的.

solution:把查询条件拼接起来,然后执行,ok

关键代码

Query query = new SolrQuery();
 
  // query.set("df", "cname");
  // query.setFilterQueries("total:[" + total + " TO " + t2 + "]");
  // query.setFilterQueries("no:" + no);
  // query.setFilterQueries("address:" + address);
  // query.setFilterQueries("dt:" + dt);
  // q=1&df=cname&fq=dt:*
  StringBuffer str = new StringBuffer();
  str.append("cname:" + cname);
  str.append(" AND total:[" + total + " TO " + t2 + "]");
  str.append(" AND no:" + no);
  str.append(" AND address:" + address);
  str.append(" AND dt:" + dt);
  query.setQuery(str.toString());
  System.out.println(query);
  // high
  query.setHighlight(true);
  query.addHighlightField("cname");
  query.setHighlightSimplePre("");
  query.setHighlightSimplePost("");
  // fenye
  QueryResponse response = s.query(query);
  int count = (int) response.getResults().getNumFound();
  PageUtils p = new PageUtils(page, count, pageSize);
  query.setStart(p.getPageRecord());
  query.setRows(p.getPageSize());
  // 执行
  QueryResponse response2 = s.query(query);
  List list = response2.getBeans(Cont.class);
  // System.out.println("list=" + list);
  Map>> highlighting = response.getHighlighting();
  // System.out.println("high=" + highlighting);
  for (Cont cont : list) {
   // 合同状态,0代表正常,1代表完工,2代表报废
   if (cont.getStatus().equals("1")) {
    cont.setStatus("完工");
   } else if (cont.getStatus().equals("2")) {
    cont.setStatus("报废");
   } else if (cont.getStatus().equals("0")) {
    cont.setStatus("正常");
   }
   if (highlighting.get(cont.getId()) == null) {
    continue;
   }
   Map> map = highlighting.get(cont.getId());
   if (map.size() == 0 || map == null) {
    continue;
   }
   List list2 = map.get("cname");
   String cname2 = cont.getCname();
   if (list2.size() > 0 && list2 != null) {
    cname2 = list2.get(0);
   }
   cont.setCname(cname2);
  }
  // mv

你可能感兴趣的:(搜索引擎)