在Lucene.net 2.9.2中突出显示整个句子 [英] Highlighting whole sentence in Lucene.net 2.9.2

查看:71
本文介绍了在Lucene.net 2.9.2中突出显示整个句子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前,我正在使用 Lucene.net 2.9.2 框架.作为搜索的结果,我希望获得带有突出显示的文本片段的结果页(asp.net).我希望所选片段是一个整个句子,而不仅仅是几个单词.

Currently I'm working with the Lucene.net 2.9.2 framework. As a result of my search I would like to achieve result page (asp.net) with highlighted text fragment. I would like that the selected fragment is a whole sentence and not only few words.

例如,如果我有文字:

Lorem ipsum dolor坐下,奉献上精英,sed do eiusmod tempor incididunt ut Labore et dolore magna aliqua.尽量不要抽烟,不要因抽烟而锻炼. Duis aute irure dolor in reprehenderit in voltate velit esse cillum dolore eu fugiat nulla pariatur. > > >

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

并且我正在搜索 cupidatat 我想得到片段:

and I'm searching for cupidatat I would like to get fragment:

感受器非偶然,偶然出现在动手的实验中.

我现在拥有的代码是:

var scorer = new QueryScorer(q);
var formatter = new SimpleHTMLFormatter("<div>", "</div>");

var highlighter = new Highlighter(formatter, scorer);
highlighter.SetTextFragmenter(new SimpleFragmenter(100));

var fragments = highlighter.GetBestFragments(stream, text, 1);

,但它仅返回大小为100的文本范围.

but it returns only text range of size 100.

如果有任何建议,我将不胜感激.

I will be thankful for any suggestion.

推荐答案

您要创建一个新的Fragmenter(类似于SimpleFragmenter).您需要调整的功能是:

You want to create a new Fragmenter (Similar to SimpleFragmenter). The function you need to adjust is:

public virtual bool IsNewFragment(Token token)
{
    bool isNewFrag = token.EndOffset() >= (fragmentSize * currentNumFrags);
    if (isNewFrag)
    {
        currentNumFrags++;
    }

    return isNewFrag;
}

在您获得正确的逻辑之前,这可能需要进行一些调整,但这应该为您提供一个很好的开端

This will likely need some adjustment until you get the correct logic, but that should give you a pretty good head start

这篇关于在Lucene.net 2.9.2中突出显示整个句子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆