What i want to do : I have a local index created with Lucene and I need to get one value for all documents in the index.
My problem is I can't read the index!
My program:
public class index {
public static void main(String[] args) {
try {
read();
} catch (CorruptIndexException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void read() throws CorruptIndexException, IOException {
System.out.println("step");
IndexReader r = IndexReader.open("D:/index/DEV_IdxDOSSIER/data/index");
System.out.println("step");
int num = r.numDocs();
for (int i = 0; i < num; i++)
{
System.out.println("step3");
Document d = r.document(i);
System.out.println("DC_KEY: ");
System.out.println(d.get("DC_KEY"));
}
/*if (!r.isDeleted(i))
{
Document d = r.document(i);
System.out.println("d=" +d);
}*/
r.close();
System.out.println("read doesn't work yet!");
}
}
Here is the error I got:
step1
java.io.IOException: read past EOF
at org.apache.lucene.store.BufferedIndexInput.refill(BufferedIndexInput.java:151)
at org.apache.lucene.store.BufferedIndexInput.readBytes(BufferedIndexInput.java:116)
at org.apache.lucene.store.BufferedIndexInput.readBytes(BufferedIndexInput.java:92)
at org.apache.lucene.store.ChecksumIndexInput.readBytes(ChecksumIndexInput.java:43)
at org.apache.lucene.store.IndexInput.readString(IndexInput.java:124)
at org.apache.lucene.index.SegmentInfo.<init>(SegmentInfo.java:148)
at org.apache.lucene.index.SegmentInfos.read(SegmentInfos.java:234)
at org.apache.lucene.index.DirectoryIndexReader$1.doBody(DirectoryIndexReader.java:95)
at org.apache.lucene.index.SegmentInfos$FindSegmentsFile.run(SegmentInfos.java:653)
at org.apache.lucene.index.DirectoryIndexReader.open(DirectoryIndexReader.java:115)
at org.apache.lucene.index.IndexReader.open(IndexReader.java:316)
at org.apache.lucene.index.IndexReader.open(IndexReader.java:206)
at indexation.index.read(index.java:152)
at indexation.index.main(index.java:49)
PS: I'm new on Lucene. I started 1 day ago and this is for a job.
I succeeded:
You must import
lucene-core-4.4.0.jar
to your library go here to read a tutorial to add lucene-core-4.4.0.This
lucene-core-4.4.0.jar
may be different for you (only the 4.4.0 would change).