Solr設置高亮


 1     @Test
 2     public void test5(){
 3         try {
 4             SolrQuery query=new SolrQuery("程序");
 5             query.setHighlight(true)
 6                 .setHighlightSimplePre("<span class='highlight'>")//設置開頭
 7                 .setHighlightSimplePost("</span>") //設置結尾
 8                 .setStart(0) 
 9                 .setRows(10);//設置行數
10             //設置高亮的哪些區域
11             query.setParam("hl.fl", "news_title,news_content");
12             QueryResponse response=httpSolrServer.query(query);
13             SolrDocumentList list=response.getResults();
14             for(SolrDocument sd:list){
15                 String id=(String) sd.getFieldValue("id");
16                 if(response.getHighlighting().get(id)!=null){
17                     System.out.println(response.getHighlighting().get(id).get("news_title"));
18 
19                     System.out.println(response.getHighlighting().get(id).get("news_content"));
20                 }
21             }
22         } catch (SolrServerException e) {
23             e.printStackTrace();
24         }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM