基于solrJ 查询 显示 分页,高亮等处理
直接贴代码:
//纠错拼写 public static String checkSpellKey(SolrQuery query, QueryResponse spellRespose) throws SolrServerException { String lastWord = ""; SpellCheckResponse spellCheckResponse = spellRespose.getSpellCheckResponse(); List<Suggestion> suggestionList = spellCheckResponse.getSuggestions(); if (suggestionList.size() > 0) { if (!spellCheckResponse.isCorrectlySpelled()) { lastWord = suggestionList.get(0).getAlternatives().toString().replace("[", "").replace("]", ""); if (lastWord.indexOf(",") > 0) { lastWord = lastWord.split(",")[0].toString(); } } query.set("q", lastWord); } return lastWord; }//文档高亮等 public static String getSolrDocument(List<SolrInforModel> list, QueryResponse qResponse, SolrDocument doc) { SolrInforModel pj = new SolrInforModel(); String id = doc.getFieldValue("id").toString(); String solrTitle = SolrStringUtils.htmlReplace(doc.getFieldValue("info_title").toString()); String solrType = SolrStringUtils.htmlReplace(doc.getFieldValue("info_type_name").toString()); pj.setId(id); String hightTitle = qResponse.getHighlighting().get(id).get("info_title") == null ? solrTitle : SolrStringUtils .htmlReplace(qResponse.getHighlighting().get(id).get("info_title").toString()); String solrContent = SolrStringUtils.htmlReplace(doc.getFieldValue("info_content").toString()); pj.setInfoContent(qResponse.getHighlighting().get(id).get("info_content") == null ? solrContent : SolrStringUtils.htmlReplace(qResponse.getHighlighting().get(id).get("info_content").toString())); pj.setInfoTitle(hightTitle); pj.setInfoTypeName(solrType); list.add(pj); return solrType; }