java.io.IOException : read past EOF Lucene in Java with Eclipse

标签 java eclipse lucene ioexception

我想要做什么:我有一个使用 Lucene 创建的本地索引,我需要为索引中的所有文档获取一个值。

我的问题是我无法读取索引!

我的程序:

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!");
    }
}

这是我得到的错误:

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:我是 Lucene 的新手。我一天前开始工作,这是为了一份工作。

最佳答案

有一个demo Lucene 发行版中包含有关如何搜索索引的信息。您可能想看一下。

关于java.io.IOException : read past EOF Lucene in Java with Eclipse,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30982388/

相关文章:

eclipse - 如何为新的 eclipse (neon) java 项目初始化 git

java - 有谁知道 NetBeans 6.x 是否可以与 Leopard 上的 Java SE 6 一起使用?

lucene - 确定lucene多字段查询中匹配哪些字段

java - {Filter}ing 是否比 Lucene 中的 {Query}ing 更快?

java - 丢弃来自套接字的输入

java - 不支持 Project facet WebSphere Web(共存)版本 8.0

java - Maven - 增加 JVM 的内存

java - 用于在 ElasticSearch 中搜索短语的分析器

java - Maven 3.8.0 编译器 - 编译时出现 fatal error : release version 11 not supported

java - 从 GAE 数据存储中读取多对多对象的最有效方法