创建lucene指数

时间:2013-06-15 16:47:58

标签: lucene

我的索引正在成功创建。我的问题是,在Luke中尝试阅读时,我收到一个错误:

Caused by: java.io.IOException: read past EOF

我知道Lucene确实提供了不存储Field的选项。但是,最好的方法是什么呢?

  • 无论大小如何,都要存储该字段,如果找到搜索的匹配项,请从文档中获取相应的字段或
  • 不存储字段,如果找到搜索的匹配,请查询数据库以获取相关信息?

以下是用于创建索引的代码:

public class CREATEiNDEX {
    /**
     * @param args
     * @throws IOException 
     */
    public static void main(String[] args) throws IOException {
        StandardAnalyzer analyzer = new StandardAnalyzer(Version.LUCENE_43);
        Directory index = FSDirectory.open(new File("C:/toturials/luceneindex/"));
        IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_43, analyzer);
        IndexWriter w = new IndexWriter(index, config);
        List <String>list=readingPersonFile();

        for (int i = 0; i < list.size(); i++)
        {
            addDoc(w, String.valueOf(i),list.get(i));
        }
        w.close();
    }

    private static void addDoc(IndexWriter w, String title, String isbn) throws IOException {
        Document doc = new Document();
        doc.add(new StringField("Id", title, Field.Store.YES));
        doc.add(new TextField("Name", isbn, Field.Store.YES));
        w.addDocument(doc);
    }

1 个答案:

答案 0 :(得分:0)

我认为你应该在删除索引后创建新索引。