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