我的索引正在成功创建。我的问题是,在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);
}
答案 0 :(得分:0)
我认为你应该在删除索引后创建新索引。