I am trying to do highlighting on the search results. Here is the relevant part of my code.

QueryScorer scorer = new QueryScorer(q);
Lucene.Net.Search.Highlight.IFormatter formatter = new SimpleHTMLFormatter("<b>", "</b>");
Lucene.Net.Search.Highlight.Highlighter highlighter = new Highlighter(formatter, scorer);
highlighter.TextFragmenter = new SimpleFragmenter(800);
Lucene.Net.Util.Version vers = new Lucene.Net.Util.Version();
vers = Lucene.Net.Util.Version.LUCENE_30;
TokenStream stream = new StandardAnalyzer(vers).TokenStream(string.Empty, new StringReader(text));

string s = string.Empty;
try
{
    s = highlighter.GetBestFragments(stream, text, 10, "...");
}

Here, GetBestFragments method throws a System.MissingMethodException. I have tried to replace the original Lucene.net dll with Lucene.Net.Contrib but this time, I dont know what I should write instead of TokenStream. It doesnt exist in Lucene.Net.Contrib.* dlls.

I am working on existing code and I need to find out how I can rewrite TokenStream class and GetBestFragments method.

Thanx

有帮助吗?

解决方案

The problem was something about deployment, that the new compatible Lucene.dll was replaced by the incompatible Sitecore7 dll.

So, if both lucene.net and lucene.net.contrib dll are referenced, it should work.

Not directly the solution to my question, but this source is worth mentioning again. (About lucene.dll versions) : http://laubplusco.net/sitecore-7-lucen-3-0-highlighted-results/

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top