一个lucene文件下会包含很多小文件,如果其中任何一个文件损坏或丢失,都会导致该lucene文件不可读,lucene在CheckIndex类中提供接口检测lucene文件是否可读。
public static void main(String[] args) {
String location = "C:/Documents and Settings/Administrator/桌面/luceneFile";
File file = new File(location);
Directory dir;
try {
dir = FSDirectory.open(file);
CheckIndex checkindex = new CheckIndex(dir);
boolean clean = checkindex.checkIndex().clean;
dir.close();
System.out.println(clean);
} catch (IOException e) {
e.printStackTrace();
}<pre name="code" class="java">}
此时clean为true,如果删除lucene文件中的一个子文件,clean为false。但是,如果删除文件名为segments.gen的文件,执行检测后,clean仍为true。这可能是lucene文件类型的问题,即使segments.gen文件丢失,依然不会影响lucene文件的正常读写。真正原因有待研究。
如果在linux下,将lucene文件的权限设置为000,“chmod -R 000 luceneFile ” ,接口检测依然会返回true。(窃以为如果lucene文件没有读权限,是不应该认为文件完好的,即应该返回false。这是lucene的问题,以后会不会变还不确定)。