2011-12-14 69 views
0

我使用Lucene HighLighter,成功。這裏是我的代碼:Lucene和突出顯示的文本字體問題

    StringBuffer sb = new StringBuffer(); 
     for (int t = 0; t < fields.length; t++) { 
      SimpleHTMLFormatter formatter = new SimpleHTMLFormatter(
        "<span class=\"highlight\">", "</span>"); 
      Highlighter highlighter = new Highlighter(formatter, 
        new QueryScorer(parser.parse(queryString))); 

      if (d.get(fields[t]) != null) { 
       hilites = highlighter.getBestFragments(analyzer, fields[t], 
         d.get(fields[t]), 3); 
       int l = hilites.length; 
       // System.out.println("hilites length: "+l); 
       if (l > 0) { 

        for (int x = 0; x < l; x++) { 
         sb.append(hilites[x]).append("..."); 
        } 

       } 
      } 

     } 

問題是在我的搜索結果/突出顯示的文本,字符是亂碼。這是由於缺少字體?

這裏是我的高亮顯示文本:

**on Educational Materials ~ ATS Job Board ""OR~C'C" .. III DUES United States Full... ? SL[I!," Full Memberhsip - Domestic membership is for residents residing in the United States. Dues...** 

通知時髦的文字!

任何幫助將不勝感激。

回答

0

'亂碼文本問題'可能與Lucene不相關,但是與XML編碼無關。您是否將'contentType'設置爲「text/html; charset = UTF-8」?

+0

感謝您的建議。我的頁面設置爲utf-8。我甚至嘗試過SimpleHTMLEncoder.htmlEncode(.....)。不好! –