日期:2014-05-17  浏览次数:20562 次

lucene.net 搜索的内容返回值的问题
//返回搜索到的字段 
result.Msg = Highlight(kw, doc.Get("msg"));


这个 doc.Get("") 默认返回了50个字 怎么调成 100个或者更多 求教

------解决方案--------------------
你索引的时候自动截取成50个字符了吧,只要存储内容,doc.get得到的就是原始的,自己检查下
------解决方案--------------------

    private static string Preview(string body, string keyword)
    {
        //创建HTMLFormatter,参数为高亮单词的前后缀 
        var simpleHTMLFormatter =
            new SimpleHTMLFormatter("<font color=\"red\">", "</font>");
        //创建 Highlighter ,输入HTMLFormatter 和 盘古分词对象Semgent 
        var highlighter =
            new Highlighter(simpleHTMLFormatter,
                            new Segment());
        //设置每个摘要段的字符数 
        highlighter.FragmentSize = 100;
        //获取最匹配的摘要段 
        String bodyPreview = highlighter.GetBestFragment(keyword, body);
        if (bodyPreview == null 
------解决方案--------------------
 bodyPreview == "")
            return body;
        return bodyPreview;
    }
//TextBox1为高亮,intor为内容,n.Intor为返回值
n.Intor = Preview(intor, TextBox1.Text);