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] -------- run: Enter query: automatically 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(String.java:1935) at org.apache.lucene.search.highlight.Highlighter.getBestTextFragments(Highlighter.java:235) at org.apache.lucene.search.highlight.Highlighter.getBestFragments(Highlighter.java:175) at org.apache.lucene.search.highlight.Highlighter.getBestFragments(Highlighter.java:460) at lucenehighlighter.SearchFiles.main(SearchFiles.java:145) Java Result: 1 BUILD SUCCESSFUL (total time: 6 seconds)
Code: -------- 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! http://in.yahoo.com/trynew