|
删除整个索引,再创建。
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();
}
}
}
}
|
|
![]() |
求解….
|
![]() 20分 |
创建索引策略是什么? IndexWriterConfig.setOpenMode(OpenMode.CREATE);
|
![]() |
没用这个。 |
![]() 20分 |
这种方式是追加的OpenMode.CREATE_OR_APPEND,你可以在main方法中先不使用index(),就可以知道是否删除了 |
![]() |
是没有setOpenMpde 谢谢 |

