2017-08-09 85 views
0

我是Solr和SolrJ的新手。我正在尝试使用桌面应用程序,并且有文件(文本文件)进行索引和搜索。我想使用高亮功能并以高亮显示片段,但是当您突出显示文本时,我不会让它们显示在黄色背景中,请让我知道如何在黄色背景中显示文本。如何使用Solrj显示突出显示的文本

这里是我的代码片段:

public void TestHighLight(SolrQuery query) throws 
       SolrServerException, IOException { 
    query.setQuery("*"); 
    query.set("hl", "true"); 
    query.set("hl.snippets", "5"); 
    query.set("q", "text:Pune"); 
    query.set("hl.fl", "*"); 
    QueryResponse queryResponse = client.query(query); 
    SolrDocumentList docs = queryResponse.getResults(); 
    Iterator iter = docs.iterator(); 
    for (int i = 0; i < docs.size(); i++) { 
     iter = docs.get(i).getFieldNames().iterator(); 
     String fldVal = (String) docs.get(i).getFieldValue("id"); 
     String docID = (String) docs.get(i).get("id"); 
     while (iter.hasNext()) { 
      String highlighText = getHighlightedText(queryResponse, 
      "text", docID); 
      System.out.println(" tHighlightedText is " + highlighText); 
     } 
    } 
} 

输出看起来是这样的:我怎么色呢? [适用于Java开发人员Pune

非常感谢!

回答

0

设置荧光笔的前后参数。指定在突出显示的术语之前使用的“标记”。这可以是任何字符串,但通常是HTML或XML标记。

e.g:

solrQueryHandler.setHighlightSimplePre("<font color="yellow">"); 
solrQueryHandler.setHighlightSimplePost("/font"); 

但是请注意,这将工作只针对原荧光笔