package com.paic.icore.ph.integration.sao.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.client.HttpClient;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.client.solrj.response.SpellCheckResponse;
import org.apache.solr.client.solrj.response.SpellCheckResponse.Suggestion;
import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrDocumentList;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import com.paic.icore.ph.integration.sao.SolrSao;
import com.paic.icore.ph.search.biz.service.SolrService;
import com.paic.icore.ph.search.biz.service.impl.AssemebleSearchResultUtil;
import com.paic.icore.ph.search.biz.service.impl.SearchServiceImpl;
import com.paic.icore.ph.search.dto.Condition;
import com.paic.icore.ph.search.dto.SearchResultDto;
import com.paic.icore.ph.search.dto.SearchResultItem;
import com.paic.icore.ph.util.SolrQueryParameterBuilderUtil;
import com.paic.pafa.biz.sao.BaseSAO;
@Component("solrSao")
public class SolrSaoImpl extends BaseSAO implements SolrSao{
	@Autowired
    private SolrService solrService;
	private HttpClient httpClient;
	Log logger=LogFactory.getLog(SearchServiceImpl.class);
	@Value("${ph.solr.baseurl}")
	private String baseUrl;
	SolrServer server = null;
	private static final String DATA_IMPORT_IDLE_STATUS = "idle";
	private static final String KNOWLEDGE_CATEGORY_PARENT_ROOT = "ROOT";

	@SuppressWarnings("unused")
	@PostConstruct
	private void init() {
		ThreadSafeClientConnManager tc = new ThreadSafeClientConnManager();
		tc.setMaxTotal(100);
		httpClient = new DefaultHttpClient(tc);
		server=new HttpSolrServer(baseUrl, httpClient);
	}

	@SuppressWarnings("unused")
	@PreDestroy
	private void destory() {
		if (httpClient != null)
			httpClient.getConnectionManager().shutdown();
	}
	public SearchResultDto zhikuService(String keyword,Integer page,Integer maxResults ,String type,List<String> deptList) throws Exception {
		
		logger.debug("keywordSearch SERVICE START");

		SearchResultDto searchResultDto=new SearchResultDto();
		ModifiableSolrParams query =new ModifiableSolrParams();
		if (null == keyword) {
			query.add("q", "keyword:*");
		} else {
			query.add("q", "keyword:" + keyword);
		}
		if ("all".equalsIgnoreCase(type)) {
			query.add("q", "type:*");
		} else {
			query.add("q", "type:" + type);
		}
		

		int startRow = ((int) page == 0) ? 0 : (page - 1)
				* maxResults;
		query.add("start", String.valueOf(startRow));
		query.add("rows", String.valueOf(maxResults));

		// 设置高亮信息
		query.add("hl", "true");// 高亮开关
		query.add("hl.fl", "title,content");// 高亮返回字段
		query.add("hl.fragsize", "150");// 高亮字段长度,0代表返回全部
		query.add("hl.encoder", "html");
		query.add("hl.fragmenter", "regex");
		query.add("hl.useFastVectorHighlighter", "true");
		query.add("f.content.hl.alternateField", "description");
		query.add("f.content.hl.maxAlternateFieldLength", "150");
	     QueryResponse response = server.query(query);
	     SolrDocumentList list = response.getResults();
 
	     Map<String, Map<String, List<String>>> map = response.getHighlighting();
	     long count = list.getNumFound();
	     System.out.println("匹配结果总数:" + count);
	     searchResultDto.setCount(count);
	     int totalPage=((int)count%maxResults==0)?(int)count/maxResults:(int)count/maxResults+1;
	     searchResultDto.setTotalPage(totalPage);//设置总页数
	     searchResultDto.setCurrentPage(page);//设置当前页
	     searchResultDto.setTotalRecord((int)count);
	     List<SearchResultItem> items=new ArrayList<SearchResultItem>();

	     SearchResultItem item=null;
	     for (SolrDocument doc : response.getResults()) {
	    	 System.out.println(doc);
	    	 item=new SearchResultItem();
	    	 //当搜索出来的类型是问问的时候
	    	 if("wenwen".equalsIgnoreCase(doc.get("type").toString())){
	    		 item=new AssemebleSearchResultUtil().assembleWenwenResult(doc,response);
	    	 }
	      	 if("jingyan".equalsIgnoreCase(doc.get("type").toString())){
	      		item=new AssemebleSearchResultUtil().assembleJinyanResult(doc,response);
	      	 }
	       	 items.add(item);
	     }
			searchResultDto.setItems(items);
			logger.debug("zhikuService: END");
			return searchResultDto;
	}

	public SearchResultDto deleteAll() throws Exception {
		server.deleteByQuery("*");
		return null;
	}

	public SearchResultDto zhikuService(Condition condition,ArrayList<String> deptList) throws Exception {
		logger.debug("zhikuService: START");
		SearchResultDto searchResultDto=new SearchResultDto();
	    //组装查询参数
		SolrQuery query=new SolrQuery();
		ModifiableSolrParams params=new ModifiableSolrParams();
		ModifiableSolrParams q=AssemebleSearchResultUtil.assembleSolrCondtion(condition,deptList);
		logger.debug("SolrQuery: params@"+q.toString());
		System.out.println(q.toString());
		QueryResponse response =null;
		try {
			response = server.query(q);
		} catch (Exception e) {
			solrService.fullImportIndex();
		}

	     SolrDocumentList list = response.getResults();
	     Map<String, Map<String, List<String>>> map = response.getHighlighting();
	     long count = list.getNumFound();
	     searchResultDto.setCount(count);
	     int totalPage=((int)count%condition.getMaxResults()==0)?(int)count/condition.getMaxResults():(int)count/condition.getMaxResults()+1;
	     searchResultDto.setTotalPage(totalPage);//设置总页数
	     searchResultDto.setCurrentPage(condition.getPage());//设置当前页
	     searchResultDto.setTotalRecord((int)count);
	     List<SearchResultItem> items=new ArrayList<SearchResultItem>();

	     SearchResultItem item=null;
	     for (SolrDocument doc : list) {
	    	 item=new SearchResultItem();
	    	 //当搜索出来的类型是问问的时候
	    	 if("wenwen".equalsIgnoreCase(doc.get("type").toString())){
	    		 item= new AssemebleSearchResultUtil().assembleWenwenResult(doc,response);
	    	 }
	      	 if("jingyan".equalsIgnoreCase(doc.get("type").toString())){
	      		item=new AssemebleSearchResultUtil().assembleJinyanResult(doc,response);
	      	 }
	       	 items.add(item);
	     }
	     searchResultDto.setItems(items);
			logger.debug("zhikuService: END");
			return searchResultDto;

	     
	     
	     
	}

	public List<String> suggestion(String str) throws Exception {
		ModifiableSolrParams params = new ModifiableSolrParams();
		params.set("qt", "/suggest");
		params.add("q", str);
		params.add("spellcheck.build", "true");
    List<String> suggestedWordList = new ArrayList<String>();  
    List<String> suggestedList = new ArrayList<String>();  
    QueryResponse response = server.query(params);
    SpellCheckResponse spellCheckResponse = response.getSpellCheckResponse();  
    List<Suggestion> suggestionList = spellCheckResponse.getSuggestions();  
    for (Suggestion suggestion : suggestionList) {  
    	
        suggestedWordList = suggestion.getAlternatives(); 
    }  

		return suggestedWordList;
	}

	@Override
	public List<String> moreLikeThis(String id, int mindf, int mintf, int count)
			throws Exception {
	      SolrQuery solrQuery = new SolrQuery();
		  solrQuery.setQuery("id:" + id)
          .setParam("fl", "id,title,content")
         .setParam("mlt", "true")
         .setParam("mlt.fl", "title")//根据哪些字段判断相似度;
         .setParam("mlt.mindf", String.valueOf(mindf))//最小文档频率,所在文档的个数小于这个值的词将不用于相似判断
         .setParam("mlt.mintf", String.valueOf(mintf))//最小分词频率,在单个文档中出现频率小于这个值的词将不用于相似判断
         .setParam("mlt.count", String.valueOf(count));
		 QueryResponse response = server.query(solrQuery);
		 if (null!=response.getResults()) {
			 SolrDocumentList list=response.getResults();
			 for (SolrDocument doc:list) {
//				 if (doc.get) {
//					   String doc_id = doc.getFieldValue("id").toString();
//	                    String doc_title = doc.getFieldValue("title").toString();                                        
//	                    String doc_url = doc.getFieldValue("url").toString();                    
//	                    String doc_score = doc.getFieldValue("score").toString();
//
//					
//				}
				
			}
			
		}
		return null;
	}
	
	

}


==================
package com.paic.icore.kms.integration.sao.impl;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.http.client.HttpClient;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import com.paic.icore.kms.biz.util.HtmlUtil;
import com.paic.icore.kms.dto.ActivitiesDTO;
import com.paic.icore.kms.dto.CustomAttrbuteDTO;
import com.paic.icore.kms.dto.KnowledgeInfoDTO;
import com.paic.icore.kms.dto.KnowledgeSearchDTO;
import com.paic.icore.kms.dto.PageInfoDTO;
import com.paic.icore.kms.integration.sao.SolrSAO;
import com.paic.icore.ph.search.biz.web.controller.SearchControler;
import com.paic.pafa.biz.sao.BaseSAO;

@Component("solrSAO")
public class SolrSAOImpl extends BaseSAO implements SolrSAO {
	private HttpClient httpClient;

	@Value("${kms.solr.baseurl}")
	private String baseUrl;

	private static final String DATA_IMPORT_IDLE_STATUS = "idle";
	private static final String KNOWLEDGE_CATEGORY_PARENT_ROOT = "ROOT";

	@SuppressWarnings("unused")
	@PostConstruct
	private void init() {
		ThreadSafeClientConnManager tc = new ThreadSafeClientConnManager();
		tc.setMaxTotal(100);
		httpClient = new DefaultHttpClient(tc);
	}

	@SuppressWarnings("unused")
	@PreDestroy
	private void destory() {
		if (httpClient != null)
			httpClient.getConnectionManager().shutdown();
	}

	private void addSolrFilterParams(KnowledgeSearchDTO searchDTO, ModifiableSolrParams params) {
		//数据库
		if (StringUtils.isNotBlank(searchDTO.getRepositoryId())) {
			params.add("fq", "repid:" + searchDTO.getRepositoryId());
		}
		if (StringUtils.isNotBlank(searchDTO.getBranchCode())) {//所属机构
			params.add("fq", "branchcode:" + searchDTO.getBranchCode());
		}
		if (StringUtils.isNotBlank(searchDTO.getSecurityLevel())) {//安全级别
			params.add("fq", "securitylevel:" + searchDTO.getSecurityLevel());
		}
		if (StringUtils.isNotBlank(searchDTO.getFormat())) {//文档格式
			String formatFilter = "";
			if("DOC".equals(searchDTO.getFormat()) || "PPT".equals(searchDTO.getFormat())){
				String newFormat = searchDTO.getFormat()+"X";
				formatFilter = "(format:" + StringUtils.lowerCase(searchDTO.getFormat())+" OR "+
					"format:" + StringUtils.lowerCase(newFormat)+")";
			}else if("EXL".equals(searchDTO.getFormat())){
				formatFilter = "(format:" + StringUtils.lowerCase(searchDTO.getFormat())+" OR format:xlsx)";
			}else{
				formatFilter = "format:" + StringUtils.lowerCase(searchDTO.getFormat());
			}
			params.add("fq", formatFilter);
		}
		if (StringUtils.isNotBlank(searchDTO.getType())) {//知识类型
			params.add("fq", "type:" + searchDTO.getType());
		}
		if (StringUtils.isNotBlank(searchDTO.getKnowtype())) {
			params.add("fq", "knowtype:" + searchDTO.getKnowtype());
		}
		if (StringUtils.isNotBlank(searchDTO.getTitle())) {//知识标题
			params.add("fq", "title:" + searchDTO.getTitle());
		}
		if (StringUtils.isNotBlank(searchDTO.getCreator())) {//创建者
			params.add("fq", "creator:" + searchDTO.getCreator());
		}
		if (StringUtils.isNotBlank(searchDTO.getStatus())) {
			params.add("fq", "status:" + searchDTO.getStatus());
		}
		if (searchDTO.getGrade() != 0) {
			params.add("fq", "grade:[" + searchDTO.getGrade() + " TO *]");
		}
		//分类 in
		if (searchDTO.getInCategoryList() != null && searchDTO.getInCategoryList().size() > 0) {
			params.add("fq", "cid:" + StringUtils.join(searchDTO.getInCategoryList().iterator(), " OR  cid:"));
		}
		//分类union
		if (searchDTO.getUnionCatgeroryList() != null && searchDTO.getUnionCatgeroryList().size() > 0) {
			params.add("fq", "cid:" + StringUtils.join(searchDTO.getUnionCatgeroryList().iterator(), " AND cid:"));
		}
		if (searchDTO.getValidDateStart() != null || searchDTO.getValidDateEnd() != null) {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
			//[2015-01-18T08:10:19Z TO 2015-01-20T08:10:19Z]
			StringBuffer sb = new StringBuffer();
			sb.append("validdate:[");
			if (searchDTO.getValidDateStart() != null) {
				sb.append(sdf.format(searchDTO.getValidDateStart()));
			} else {
				sb.append("*");
			}
			sb.append(" TO ");
			if (searchDTO.getValidDateEnd() != null) {
				sb.append(sdf.format(searchDTO.getValidDateEnd()));
			} else {
				sb.append("*");
			}
			sb.append("]");
			params.add("fq", sb.toString());
		}
		//总部用户--按用户专业、岗位限制
		if(StringUtils.isNotBlank(searchDTO.getAuthExpert())){  
			String expertFilter = "cid:"+searchDTO.getAuthExpert()+" OR (NOT cid:"+
				searchDTO.getAuthExpert()+" AND customattr:"+searchDTO.getPostCode()+" AND (";
			if(StringUtils.isNotEmpty(searchDTO.getAuthPost())){
				expertFilter += "customattr:"+searchDTO.getAuthPost()+" OR ";
			}
			expertFilter += "customattr:"+searchDTO.getPostCodeAll()+"))"; 
			params.add("fq", expertFilter);
		}
		//普通用户和机构用户--按机构和岗位限制
		//找出相同attrcode的值,不同attrcode是且的关系,相同的attrcode是or的关系
		if (searchDTO.getCustomAttrbuteList() != null && searchDTO.getCustomAttrbuteList().size() > 0) {
			Map<String,List<String>> custAttrMap=new HashMap<String, List<String>>();
			for (CustomAttrbuteDTO attrDto : searchDTO.getCustomAttrbuteList()) {
				List<String> valList = custAttrMap.get(attrDto.getAttrCode());
				if(valList==null){
					valList = new ArrayList<String>();
					custAttrMap.put(attrDto.getAttrCode(), valList);
				}
				custAttrMap.get(attrDto.getAttrCode()).add(attrDto.getAttrVal());
			}
			Iterator<Entry<String, List<String>>> it = custAttrMap.entrySet().iterator();
			while (it.hasNext()) {
				Entry<String, List<String>> entry = it.next();
				StringBuffer sb = new StringBuffer();
				sb.append("(customattr:");
				sb.append(entry.getKey());
				sb.append(" AND ");
				sb.append("(");
				List<String> values = entry.getValue();
				for (int i = 0; i < values.size(); i++) {
					if (i > 0) {
						sb.append(" OR ");
					}
					sb.append("customattr:" + values.get(i));
				}
				sb.append("))");
				logger.info("自定义属性过滤条件为:" + sb.toString());
				params.add("fq", sb.toString());
			}
		}
	}

	private void addSolrHightLightParams(KnowledgeSearchDTO searchDTO, ModifiableSolrParams params) {
		String searchTerm = searchDTO.getSearchTerm();
		params.add("hl", "true");//高亮开关
		params.add("hl.fl", "title,content");//高亮返回字段
		params.add("hl.fragsize", "150");//高亮字段长度,0代表返回全部
		params.add("hl.encoder", "html");
		params.add("hl.fragmenter", "regex");
		params.add("hl.useFastVectorHighlighter", "true");
		params.add("f.content.hl.alternateField", "description");
		params.add("f.content.hl.maxAlternateFieldLength", "150");
		if (StringUtils.isNotBlank(searchTerm)) {
			if (searchTerm.matches("[0-9]*") || searchTerm.indexOf("*") > -1) {
				params.add("hl.q", searchTerm.replaceAll("\\*", ""));
			}
		}
	}

	private void addSolrBasicParams(KnowledgeSearchDTO searchDTO, ModifiableSolrParams params) {
		params.set("qt", "/select");
		params.add("defType", "edismax");
		params.add("fl", "kid,title,validdate,modifier,score,branchcode,cname,pid,type,createddate,grade,knowtype,securitylevel,hitcount,gradenum");
		String searchTerm = searchDTO.getSearchTerm();
		if (StringUtils.isNotBlank(searchTerm)) {
			if (searchTerm.matches("[0-9]*")) {
				params.add("q", searchTerm + "*");
			} else {
				params.add("q", searchTerm);
			}
		} else {
			params.add("q", "*:*");
		}

		String searchField = searchDTO.getSearchField();
		if (StringUtils.isBlank(searchField)) {
			params.add("qf", "alltext");
		} else if (KnowledgeSearchDTO.FIELD_CONTENT.equals(searchField)) {
			params.add("qf", "content");
		} else if (KnowledgeSearchDTO.FIELD_TITLE.equals(searchField)) {
			params.add("qf", "title");
		} else if (KnowledgeSearchDTO.FIELD_CREATOR.equals(searchField)) {
			params.add("qf", "creator");
		} else {
			params.add("qf", "alltext");
		}
	}

	private void addSolrSortParams(String sortType, ModifiableSolrParams params) {
		if (KnowledgeSearchDTO.SORT_BY_VALID_DATE_DESC.equals(sortType)) {
			params.add("sort", "validdate desc");
		} else if (KnowledgeSearchDTO.SORT_BY_HITCOUNT_DESC.equals(sortType)) {
			params.add("sort", "hitcount desc");
		} else if (KnowledgeSearchDTO.SORT_BY_COMMENTCOUNT_DESC.equals(sortType)) {
			params.add("sort", "commentnum desc");
		} else if (KnowledgeSearchDTO.SORT_BY_GRADE_DESC.equals(sortType)) {
			params.add("sort", "grade desc");
		} else if (KnowledgeSearchDTO.SORT_BY_GRADECOUNT_DESC.equals(sortType)) {
			params.add("sort", "gradenum desc");
		} else if (KnowledgeSearchDTO.SORT_BY_VALID_DATE_ASC.equals(sortType)) {
			params.add("sort", "validdate asc");
		} else if (KnowledgeSearchDTO.SORT_BY_HITCOUNT_ASC.equals(sortType)) {
			params.add("sort", "hitcount asc");
		} else if (KnowledgeSearchDTO.SORT_BY_COMMENTCOUNT_ASC.equals(sortType)) {
			params.add("sort", "commentnum asc");
		} else if (KnowledgeSearchDTO.SORT_BY_GRADE_ASC.equals(sortType)) {
			params.add("sort", "grade asc");
		} else if (KnowledgeSearchDTO.SORT_BY_GRADECOUNT_ASC.equals(sortType)) {
			params.add("sort", "gradenum asc");
		} else if (KnowledgeSearchDTO.SORT_BY_MODIFYDATE_DESC.equals(sortType)) {
			params.add("sort", "modifieddate desc");
		} else if (KnowledgeSearchDTO.SORT_BY_MODIFYDATE_ASC.equals(sortType)) {
			params.add("sort", "modifieddate asc");
		}else {
			params.add("sort", "modifieddate desc");
		}
	}

	@SuppressWarnings("unchecked")
	private List<KnowledgeInfoDTO> solrResponse2KnowledgeInfoList(QueryResponse response) {
		List<KnowledgeInfoDTO> infoList = new ArrayList<KnowledgeInfoDTO>();
		for (SolrDocument document : response.getResults()) {
			String kid = (String) document.getFieldValue("kid");
			KnowledgeInfoDTO infoDTO = new KnowledgeInfoDTO();
			infoDTO.setKid(kid);
			infoDTO.setValidDate((Date) document.getFieldValue("validdate"));
			infoDTO.setBranchCode((String)document.getFieldValue("branchcode"));
			infoDTO.setKnowType((String)document.getFieldValue("knowtype"));  //资源类型
			infoDTO.setCreateDate((Date)document.getFieldValue("createddate"));
			infoDTO.setSources((String)document.getFieldValue("securitylevel"));  //爬虫资源url
			infoDTO.setType((String)document.getFieldValue("type"));//rfc type
			ActivitiesDTO actDTO=new ActivitiesDTO();
			Object pObject =(Integer)document.getFieldValue("grade");
			if (pObject==null){
				actDTO.setGrade(0);
			}else{
				actDTO.setGrade((Integer)document.getFieldValue("grade"));
				pObject=null;
			}
			 pObject =(Integer)document.getFieldValue("gradenum");
			if (pObject==null){
				actDTO.setGradeCount(0);
			}else{
				actDTO.setGradeCount((Integer)document.getFieldValue("gradenum"));
			}
			
			infoDTO.setActivities(actDTO);
			List<String> cname = (List<String>) document.getFieldValue("cname");  //专业分类名称
			List<String> pids = (List<String>) document.getFieldValue("pid"); //专业分类父ID
			if(cname != null && cname.size() > 0){
				if(pids != null && pids.size() > 0){
					for(int i=0; i<pids.size(); i++){
						if(KNOWLEDGE_CATEGORY_PARENT_ROOT.equals(pids.get(i))){
							infoDTO.setType(cname.get(i));
						}
					}
				}
			}
			List<String> modifyUser = (List<String>) document.getFieldValue("modifier");
			if (modifyUser != null) {
				infoDTO.setModifyUser(StringUtils.join(modifyUser.iterator(), ""));
			}
			List<String> title = (List<String>) document.getFieldValue("title");
			if (title != null) {
				infoDTO.setTitle(StringUtils.join(title.iterator(), ""));
			}
			if (response.getHighlighting() != null && response.getHighlighting().get(kid) != null) {
				List<String> highlightSnippets = response.getHighlighting().get(kid).get("title");
				if (highlightSnippets != null) {
					infoDTO.setTitle(StringUtils.join(highlightSnippets.iterator(), ""));
				}
				List<String> highlightContentSnippets = response.getHighlighting().get(kid).get("content");
				 StringBuffer sb=new StringBuffer("");
				if (highlightContentSnippets != null) {
					sb.append(StringUtils.join(highlightContentSnippets.iterator(), ""));
				}
				List<String> highlightSubjectSnippets = response.getHighlighting().get(kid).get("subject");
				if (highlightSubjectSnippets != null) {
					sb.append(StringUtils.join(highlightSubjectSnippets.iterator(), ""));
				}
				if(!sb.toString().equals("")){
					infoDTO.setContent(HtmlUtil.getTextFromHtml(StringEscapeUtils.unescapeHtml(sb.toString())));
				}
				
			}
			infoList.add(infoDTO);
		}
		return infoList;
	}

	@Override
	public PageInfoDTO fullTextSearch(KnowledgeSearchDTO searchDTO, PageInfoDTO pageInfoDTO) {
		org.apache.commons.logging.Log logger=org.apache.commons.logging.LogFactory.getLog(SearchControler.class);
		logger.debug("fullTextSearchSolrSAO start:@"+baseUrl);
		ModifiableSolrParams params = new ModifiableSolrParams();
		addSolrBasicParams(searchDTO, params);
		params.add("start", String.valueOf(pageInfoDTO.getOffset()));
		params.add("rows", String.valueOf(pageInfoDTO.getLimit()));
		addSolrFilterParams(searchDTO, params);
		addSolrHightLightParams(searchDTO, params);
		addSolrSortParams(searchDTO.getSort(), params);

		SolrServer server = new HttpSolrServer(baseUrl, httpClient);
		PageInfoDTO result = pageInfoDTO;
		try {
			QueryResponse response = server.query(params);
			result.setTotal(response.getResults().getNumFound());
			result.setList(solrResponse2KnowledgeInfoList(response));
		} catch (SolrServerException e) {
			logger.error("全文检索异常。", e);
		}
		return pageInfoDTO;
	}

	private String querySharedServerDataImportStatus(SolrServer server) {
		String importStatus = DATA_IMPORT_IDLE_STATUS;
		ModifiableSolrParams params = new ModifiableSolrParams();
		params.add("qt", "/indexversion");
		params.add("command", "dataimportstatus");
		try {
			QueryResponse response = server.query(params);
			importStatus = (String) response.getResponse().get("dataimporstatus");
		} catch (SolrServerException e) {
			logger.error("查询solr导入状态失败" + System.currentTimeMillis(), e);
		}
		return importStatus;
	}
	
	public void deltalImportIndex() {
		SolrServer server = new HttpSolrServer(baseUrl, httpClient);
		if (!querySharedServerDataImportStatus(server).equalsIgnoreCase(DATA_IMPORT_IDLE_STATUS))
			return;
		ModifiableSolrParams params = new ModifiableSolrParams();
		params.add("qt", "/dataimport");
		params.add("command", "delta-import");
		params.add("commit", "true");
		try {
			server.query(params);
		} catch (SolrServerException e) {
			logger.error("增量导入失败。" + System.currentTimeMillis(), e);
		}
	}
}

===================
基本参数:params.set("qt", "/select");
		params.add("defType", "edismax");
		params.add("fl", "kid,title,validdate,modifier,score,branchcode,cname,pid,type,createddate,grade,knowtype,securitylevel,hitcount,gradenum");--fl可在solrconfig.xml配置		
q 查询的关键字
qf 指定从哪些字段搜索,不指定就是从所有字段.可设置权重 ("qf","title^1 price^0.1")
"bf", "sum(abs(price))" 权重更改,可不设置
start,rows
fq(filterQuery):最好分开普通过滤和可见性过滤
hl
sort



 

帖子状态

话题参与者

回复显示排序:

给大家安利一款免费的在线流程图设计软件:贼好用 ProcessFlow — 免费在线作图、实时协作 ProcessFlow是一个在线作图工具的聚合平台, 它可以在线画流程图、思维导图、UI原型图、UML、网络拓扑图、组织结构图等等, 您无需担心下载和更新的问题, 不管Mac还是Windows,一个浏览器就可以随时随地的发挥创意,规划工作,解放您的双手,让您腾出双手去成就别人的梦想。

Finally!
有没有特别的设计建议或更新的指南?
Finally!
您好,这边没有的。
tesla02 best answer
6 Jan,2019
Finally!
有没有特别的设计建议或更新的指南?
此帖子已被版主标记,收到太多否决票。

这是太大的预览图像,它应该更小,甚至五行。在一个页面上有30到60个页面,它是1800个项目 类别例如在附加组件类别有22749个项目,为什么不看到所有的项目,但只有那1800个项目?这是件坏事。

看起来您是个新人,欢迎免费注册社区,加入我们的大家庭,一起学习,一起成长。
提交你的评论
System.out.println("请输入你的代码块...");
话题
分类
喜欢
回复
浏览
活跃
原创社区
985
0
1.5k
原创社区
985
1
1.5k
20/12/25 22:32:21
javaWeb
985
1
1.5k
20/06/15 22:09:21
youtube
698
78
2.1k
3d
Settings

请插入代码块