Lucene索引删除有关问题

Lucene索引删除问题
删除整个索引,再创建。
运行后发现,删除、创建方法都执行了,但索引都还在。最后出现了创建的4个索引都存在的情况。
在删除方法里加上commit也还是删不掉。

public static void main(String[] args) throws IOException {
for (int i = 0; i < 4; i++) {
System.out.println("删除索引1");
deleteAllIndex();
System.out.println("删除索引2");
System.out.println("创建索引1");
index();
System.out.println("创建索引2");
}
}


删除索引的方法:

public static boolean deleteAllIndex() throws IOException {
try {
getIndexWriter().deleteAll();
getIndexWriter().commit();
// getIndexWriter().forceMerge(1);
// getIndexWriter().forceMergeDeletes();
return true;
} catch (Exception e) {
return false;
} finally {
if (indexWriter != null) {
try {
indexWriter.close();
indexWriter = null;
} catch (Exception e) {
e.printStackTrace();
}
}
}
}

------解决思路----------------------
创建索引策略是什么? IndexWriterConfig.setOpenMode(OpenMode.CREATE);
------解决思路----------------------
引用:
Quote: 引用:

创建索引策略是什么? IndexWriterConfig.setOpenMode(OpenMode.CREATE);

没用这个。
直接用这个的:IndexWriterConfig indexWriterConfig = new IndexWriterConfig(Version.LUCENE_43, new StandardAnalyzer(Version.LUCENE_43));

这种方式是追加的OpenMode.CREATE_OR_APPEND,你可以在main方法中先不使用index(),就可以知道是否删除了