Hi,
I have a problem with lucene highlighter. I couldn’t make it run. The
compilation is without error but when I run it I got this error “Exception
in thread "main"
java.lang.NoSuchMethodError:org.apache.lucene.analysis.TokenStream.next(Lorg/apache/lucene/analysis/Token;)Lorg/apache/lucene/analysis/Token;”
I am using lucene 3.0.3 core and lucene highlighter 2.4. It might be a
problem of compatibility. I tried to use lucene highlighter 3. but I
couldn’t combile he code and I got this error “SpanScorer can’t be resolved
as a type”
Here part of the code:
import org.apache.lucene.search.highlight.Fragmenter;
import org.apache.lucene.search.highlight.Highlighter;
import org.apache.lucene.search.highlight.SimpleSpanFragmenter;
import org.apache.lucene.search.highlight.SpanScorer;
import org.apache.lucene.search.highlight.TokenSources;
.
.
.
for (int i = start; i < end; i++) {
if (raw) { // output raw format
System.out.println("doc="+hits[i].doc+" score="+hits[i].score);
continue;
}
Document doc = searcher.doc(hits[i].doc);
String path = doc.get("path");
contents=doc.get("contents");
// System.out.println(text+" !!!!!!!!!!!!!!!!!");
fragments = getFragmentsWithHighlightedTerms(analyzer, query, "contents",
contents, 5, 100);
.
.
private static String[] getFragmentsWithHighlightedTerms(Analyzer analyzer,
Query query,String fieldName, String fieldContents, int fragmentNumber,
int fragmentSize) throws IOException
{
TokenStream stream = TokenSources.getTokenStream(fieldName, fieldContents,
analyzer);
SpanScorer scorer = new SpanScorer(query, fieldName, new
CachingTokenFilter(stream));
Fragmenter fragmenter = new SimpleSpanFragmenter(scorer, fragmentSize);
Highlighter highlighter = new Highlighter(scorer);
highlighter.setTextFragmenter(fragmenter);
highlighter.setMaxDocCharsToAnalyze(Integer.MAX_VALUE);
String[] summaries = highlighter.getBestFragments(new
StandardAnalyzer(Version.LUCENE_CURRENT), fieldContents,contents, 3);
System.out.println(summaries);
// String[] fragments = highlighter.getBestFragments(stream, fieldContents,
fragmentNumber);
return fragments;
}
Thanks in advance
--
View this message in context:
http://lucene.472066.n3.nabble.com/lucene-highlighter-tp3522464p3522464.html
Sent from the Lucene - Java Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]