• Solr 后台查询实例 (工作备查)


    有时间再进行整理
    package
    xxx.service.impl; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; import org.apache.commons.beanutils.BeanUtils; import org.apache.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.client.RestTemplate; import com.google.common.base.Joiner; import xxx.config.ApplicationProperties; import xxx.dbmodel.Copyright; import xxx.repository.generic.CopyrightGenericRepository; import xxx.service.CopyrightService; import xxx.web.rest.util.StringUtil; @Service @Transactional public class CopyrightServiceImpl implements CopyrightService { private static final Logger log = Logger.getLogger(CopyrightServiceImpl.class); @Autowired private ApplicationProperties applicationProperties; @Autowired private CopyrightGenericRepository copyrightGenericTRepository; @Qualifier("solrRestTemplate") @Autowired private RestTemplate restTemplate; @Override public Copyright getOneById(String id) { return copyrightGenericTRepository.getOneById(id); } @Override public String getPageFromSolr(Copyright copyright, int page, int rows, String sidx, String sord) { //查询参数Map Map<String, Object> paramsMap = new HashMap<>(); Map<String, String> copyrightFields = new HashMap<>(); try { copyrightFields = BeanUtils.describe(copyright); } catch (Exception e) { log.info("search parms is error in CopyrightFieldsServiceImpl!", e); } for (Entry<String,String> field : copyrightFields.entrySet()) { String key = field.getKey(); String value = field.getValue(); if(StringUtil.isNullStr(value) || "class".equals(key)){ continue; } if(key.endsWith("Id")){ paramsMap.put(key, value); }else{ paramsMap.put(key, "*"+value+"*"); } } //指定查询表名 paramsMap.put("searchType", "CopyrightMG"); if(copyright.getBeginTime() != null){ paramsMap.put("beginTime","["+copyright.getBeginTime()+" TO * ]"); } if(copyright.getEndTime() != null){ paramsMap.put("endTime","[ * TO "+copyright.getEndTime()+" ]"); } //查询条件Map Map<String, Object> queryMap = setQueryMap(paramsMap, page, rows, sidx, sord); //solr查询 return restTemplate.postForObject(applicationProperties.getStorage().getSorlUrl(), queryMap, String.class); } private Map<String, Object> setQueryMap(Map<String, Object> paramsMap, int page, int rows, String sidx, String sord){ Map<String, Object> query = new HashMap<>(); String paramStr = Joiner.on(",").withKeyValueSeparator(":").join(paramsMap); query.put("filterQueries", paramStr); query.put("query", "*:*"); query.put("start", (page-1)*rows);//开始位置 query.put("rows", rows);//查询条数 String sort = "copyrightId desc"; if(!StringUtil.isNullStr(sidx)){ sort = sidx + " " + sord; } query.put("sort", sort); //指定查询数媒集合 query.put("collection", applicationProperties.getStorage().getSorlIndexLibrary()); query.put("returnType", "1"); return query; } @Override public Long count() { return copyrightGenericTRepository.count(); } }
  • 相关阅读:
    VS2013编写的C#程序,在xp下会报错说“不是合法的win32程序”。
    能根据串口驱动来 确定com号
    javaweb工程,Servlet里面获取当前WEB跟路径的文件绝对路径地址
    import了sun开头的类,虽然它在代码里压根就没派上用处!但是必须得引用!
    页面关闭时触发的时间
    jquery设置元素的readonly和disabled
    ibatis CDATA
    form的submit与onsubmit的用法与区别
    C#操作AD及Exchange Server总结(一)
    AD如何用C#进行增删改、查询用户与OU
  • 原文地址:https://www.cnblogs.com/slowcity/p/9008264.html
Copyright © 2020-2023  润新知