Portlet using lucene gives ArrayIndexOutOfBoundsException
francsi Dec 8, 2006 7:23 AMHello!
I've buld a Portlet using the apache lucene API to search our website.
Indexing will be performed as a job in java (works fine).
My portlet is using the following method to do a simple search:
private static List sucheSchlagwort(String queries)throws Exception{
String index = "index";
String field = "contents";
int repeat = 0;
boolean raw = false;
String normsField = null;
//
//
IndexReader reader = IndexReader.open(index);
if (normsField != null)
reader = new OneNormsReader(reader, normsField);
Searcher searcher = new IndexSearcher(reader);
Analyzer analyzer = new StandardAnalyzer();
BufferedReader in = null;
// in = new BufferedReader(new FileReader(queries));
QueryParser parser = new QueryParser(field, analyzer);
List alleErgebnisse = new ArrayList();
String line = queries; // in.readLine();
Query query = parser.parse(line);
Hits hits = searcher.search(query);
// ANFANG
// FIXME: Ausgabe ins Ausgabeportlet, nicht println
for (int i = 0; i < hits.length(); i++) {
Ergebnis ergebnis = new Ergebnis();
Document doc = hits.doc(i);
String path = doc.get("path");
if (path != null) {
ergebnis.setLink(doc.get("path"));
System.out.println(doc.get("path"));
String title = doc.get("title");
if (title != null) {
ergebnis.setTitel(doc.get("title"));
System.out.println(doc.get("title"));
}
} else {
ergebnis.setLink("Kein Link zu diesem Dokument vorhanden");
}
alleErgebnisse.add(ergebnis);
if (queries != null) // non-interactive
break;
}
// ENDE
reader.close();
return alleErgebnisse;
}
Implementet into a simple java class it works fine on shell. Started as part of my portlet, it sends me the following error:
2006-12-08 12:34:42,393 ERROR [STDERR] java.lang.ArrayIndexOutOfBoundsException: -1 2006-12-08 12:34:42,393 ERROR [STDERR] at java.util.ArrayList.get(ArrayList.java:323) . . . 2006-12-08 12:34:42,413 ERROR [STDERR] at org.apache.lucene.index.IndexReader.open(IndexReader.java:95) 2006-12-08 12:34:42,413 ERROR [STDERR] at SuchportletPortlet.sucheSchlagwort(SuchportletPortlet.java:54) . . .
Looks like it comes from here:
IndexReader reader = IndexReader.open(index);
Changing the index to a non existing path sends an error that the path is not existing. So there must be a problem with reading the index. Don't you think?
What about the read/write permissions under the JBOSS directory?
And remember... in a standard java program it works...
Greetings,
Jan