Hi, it looks like your classpath is containing also very old Lucene versions together with the new Lucene JAR file. Alternatively it may also be the case that contrib-highlighter.jar, contrib-memory.jar and lucene-core.jar are not from the same Lucene version. The method next(Token) is only available in ancient Lucene versions (pre-3.0). If you are using Eclipse it may be the case, that the very old Lucene versions shipped with your Eclipse installation somehow made it into your classpath.
Uwe ----- Uwe Schindler H.-H.-Meier-Allee 63, D-28213 Bremen http://www.thetaphi.de eMail: u...@thetaphi.de > -----Original Message----- > From: starz10de [mailto:farag_ah...@yahoo.com] > Sent: Sunday, November 20, 2011 10:53 AM > To: java-user@lucene.apache.org > Subject: lucene highlighter > > 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(Lo > rg/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: java-user-unsubscr...@lucene.apache.org > For additional commands, e-mail: java-user-h...@lucene.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org For additional commands, e-mail: java-user-h...@lucene.apache.org