lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From DHIVYA M <>
Subject Error while implementing HIGHLIGHTER
Date Sat, 31 Oct 2009 06:01:27 GMT
Hi all,
While attempting to use highlighter with lucene 2.3.2 to get the result similar to that of
google response am getting the following error. 
Kindly give me a solution for this problem or provide me an alternate coding methodology if
this s ultimately wrong. I couldnt find out where am missing.
Error: [as viewed through Netbeans 6.5.1]
Enter query: 
Searching for: automatically
1 total matching documents
1. d:\test\new.txt
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of
range: 23
        at java.lang.String.substring(
        at lucenehighlighter.SearchFiles.main(
Java Result: 1
BUILD SUCCESSFUL (total time: 6 seconds)

SimpleHTMLFormatter formatter = new SimpleHTMLFormatter( 
"<span class=\"highlight\">", "</span>"); 
Highlighter high= new Highlighter(formatter,new QueryScorer(query));
high.setTextFragmenter(new SimpleFragmenter(20));
for (int j = 0; j < hits.length(); j++) {
 String text = hits.doc(j).get("path");
  TokenStream tokenStream = analyzer.tokenStream("contents", new FileReader(text));
  String result = high.getBestFragments(tokenStream,text,5,"...");
  System.out.println("\t" + result);

      From cricket scores to your friends. Try the Yahoo! India Homepage!
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message