java.io.IOException:通过Eclipse读取java中的EOF Lucene
我想做什么:我用Lucene创建了一个本地索引,需要为索引中的所有文档获取一个值 我的问题是我看不懂索引强> 我的节目:java.io.IOException:通过Eclipse读取java中的EOF Lucene,java,eclipse,lucene,ioexception,Java,Eclipse,Lucene,Ioexception,我想做什么:我用Lucene创建了一个本地索引,需要为索引中的所有文档获取一个值 我的问题是我看不懂索引 我的节目: public class index { public static void main(String[] args) { try { read(); } catch (CorruptIndexException e) { // TODO Auto-generated catch block
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!");
}
}
公共类索引{
公共静态void main(字符串[]args){
试一试{
read();
}捕获(腐蚀异常e){
//TODO自动生成的捕捉块
e、 printStackTrace();
}捕获(IOE异常){
//TODO自动生成的捕捉块
e、 printStackTrace();
}
}
public static void read()引发CorruptIndexException,IOException{
System.out.println(“步骤”);
IndexReader r=IndexReader.open(“D:/index/DEV_IdxDOSSIER/data/index”);
System.out.println(“步骤”);
int num=r.numDocs();
for(int i=0;i
以下是我得到的错误:
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)
step1
java.io.IOException:读取超过EOF
位于org.apache.lucene.store.BufferedIndexInput.refill(BufferedIndexInput.java:151)
位于org.apache.lucene.store.BufferedIndexInput.readBytes(BufferedIndexInput.java:116)
位于org.apache.lucene.store.BufferedIndexInput.readBytes(BufferedIndexInput.java:92)
位于org.apache.lucene.store.ChecksumIndexInput.readBytes(ChecksumIndexInput.java:43)
位于org.apache.lucene.store.IndexInput.readString(IndexInput.java:124)
位于org.apache.lucene.index.SegmentInfo.(SegmentInfo.java:148)
位于org.apache.lucene.index.SegmentInfos.read(SegmentInfos.java:234)
在org.apache.lucene.index.DirectoryIndexReader$1.doBody上(DirectoryIndexReader.java:95)
在org.apache.lucene.index.SegmentInfos$FindSegmentsFile.run(SegmentInfos.java:653)
位于org.apache.lucene.index.DirectoryIndexReader.open(DirectoryIndexReader.java:115)
位于org.apache.lucene.index.IndexReader.open(IndexReader.java:316)
位于org.apache.lucene.index.IndexReader.open(IndexReader.java:206)
读取(index.java:152)
在index.index.main处(index.java:49)
附言:我是Lucene的新手。我一天前开始工作,这是为了一份工作 Lucene发行版中包含了一个关于如何搜索索引的主题。您可能想看看这一点。Lucene发行版中包含了一个关于如何搜索索引的说明。你可能想看看这个。我成功了:
public static void read() throws IOException {
System.out.println("Etape1");
File indexDirectory = new File("D:/index/DEV_IdxDOSSIER/data/index");
IndexReader r = IndexReader.open(FSDirectory.open(indexDirectory));
System.out.println("Etape2");
int num = r.numDocs();
int nbrUA = 0 ;
for (int i = 0; i < num; i++) {
Document d = r.document(i);
System.out.println("DC_KEY: " + d.get("DC_KEY"));
try {
FileWriter fw = new FileWriter("D:\\index\\test.txt", true);
BufferedWriter output = new BufferedWriter(fw);
if (d.get("DC_KEY") != null) {
output.write(d.get("DC_KEY") + "\r\n");
System.out.println("fichier mis à jour");
} else {
System.out.println("Le DC_KEY est null c'est une Unité d'Archive");
nbrUA++;
}
output.flush();
output.close();
} catch (IOException ioe) {
System.out.println("the fonction write didn't Work, here is the Error");
ioe.printStackTrace();
} catch (NullPointerException ioe) {
System.out.println("Erreur : pointeur null");
System.out.println("the fonction write didn't Work, here is the Error");
ioe.printStackTrace();
}
System.out.println("nombre de document traité : " + (i + 1) + "\r\n");
}
r.close();
System.out.println("nombre d'Unité d'Archive : " + nbrUA + "\r\n");
}
public static void read()引发IOException{
系统输出打印项次(“Etape1”);
File indexDirectory=新文件(“D:/index/DEV_IdxDOSSIER/data/index”);
IndexReader r=IndexReader.open(FSDirectory.open(indexDirectory));
系统输出打印项次(“Etape2”);
int num=r.numDocs();
int nbrUA=0;
for(int i=0;i
您必须将lucene-core-4.4.0.jar导入到您的库中去阅读添加lucene-core-4.4.0的教程
这个lucene-core-4.4.0.jar对您来说可能不同(只有4.4.0会改变)。我成功了:
public static void read() throws IOException {
System.out.println("Etape1");
File indexDirectory = new File("D:/index/DEV_IdxDOSSIER/data/index");
IndexReader r = IndexReader.open(FSDirectory.open(indexDirectory));
System.out.println("Etape2");
int num = r.numDocs();
int nbrUA = 0 ;
for (int i = 0; i < num; i++) {
Document d = r.document(i);
System.out.println("DC_KEY: " + d.get("DC_KEY"));
try {
FileWriter fw = new FileWriter("D:\\index\\test.txt", true);
BufferedWriter output = new BufferedWriter(fw);
if (d.get("DC_KEY") != null) {
output.write(d.get("DC_KEY") + "\r\n");
System.out.println("fichier mis à jour");
} else {
System.out.println("Le DC_KEY est null c'est une Unité d'Archive");
nbrUA++;
}
output.flush();
output.close();
} catch (IOException ioe) {
System.out.println("the fonction write didn't Work, here is the Error");
ioe.printStackTrace();
} catch (NullPointerException ioe) {
System.out.println("Erreur : pointeur null");
System.out.println("the fonction write didn't Work, here is the Error");
ioe.printStackTrace();
}
System.out.println("nombre de document traité : " + (i + 1) + "\r\n");
}
r.close();
System.out.println("nombre d'Unité d'Archive : " + nbrUA + "\r\n");
}
public static void read()引发IOException{
系统输出打印项次(“Etape1”);
File indexDirectory=新文件(“D:/index/DEV_IdxDOSSIER/data/index”);
IndexReader r=IndexReader.open(FSDirectory.open(indexDirectory));
系统输出打印项次(“Etape2”);
int num=r.numDocs();
int nbrUA=0;
for(int i=0;i