我正在尝试将 Lucene.NET Highlighter 添加到我的搜索中,但是它做了一些非常奇怪的突出显示,我做错了什么?
下面是高亮代码:
// stuff here to get scoreDocs
var content = doc.GetField("content").StringValue();
// content = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been"
var highlighter = new Highlighter(new StrongFormatter(), new HtmlEncoder(), new QueryScorer(query.Rewrite(indexSearcher.GetIndexReader())));
highlighter.SetTextFragmenter(new SimpleFragmenter(100));
var tokenStream = analyzer.TokenStream("content", new StringReader(content));
var bestFragment = highlighter.GetBestFragment(tokenStream, content);
搜索给"lorem"
了我这个 bestFragment 值:
<strong>Lorem</strong> <strong>Ipsum</strong> is <strong>simply</strong> <strong>dummy</strong> <strong>text</strong> of the <strong>printing</strong> and <strong>typesetting</strong> <strong>industry</strong>. <strong>Lorem</strong> <strong>Ipsum</strong> <strong>has</strong> <strong>been</strong>
如您所见,它突出显示的不仅仅是"Lorem"
. 为什么?
我如何使这个行为明智?
我正在使用 aStandardAnalyzer
我的查询看起来像"content:lorem"
*编辑:*我使用 Lucene.NET 2.9.2
谢谢