【问题标题】:Lucene and Highlighted text font issuesLucene 和高亮文本字体问题
【发布时间】:2017-06-14 06:29:34
【问题描述】:

我正在使用 Lucene HighLighter,成功了。这是我的代码:

                    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...**

注意时髦的文字!

任何帮助将不胜感激。

【问题讨论】:

    标签: fonts lucene lucene-highlighter


    【解决方案1】:

    “乱码问题”可能与 Lucene 无关,而是与 XML 编码有关。您是否将“contentType”设置为“text/html;charset=UTF-8”?

    【讨论】:

    • 感谢您的建议。我的页面设置为 utf-8。我什至尝试过 SimpleHTMLEncoder.htmlEncode(.....)。不好!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多