最近正在做全文搜索。
问题是我新增索引后,旧的索引文件不能删除?
建索引代码如下:
Directory directory;
IndexWriter writer;
CWordAnalyzer analyzer=new CWordAnalyzer();
directory = FSDirectory.getDirectory(indexFilePath, false);
if(IndexReader.isLocked(directory)){ //这两行是我后加的,以为加上之后,就可以了,但还是不行
IndexReader.unlock(directory);
}
writer = new IndexWriter(directory, analyzer, false);
Statement stmt=conwl.createStatement();
String sql="select id, sm, dj, fl, bb, bbbh, flbh from e_ysmxi where indexstatus=0 ";
ResultSet rst=stmt.executeQuery(sql);
while(rst.next()){
Document doc = new Document();
doc.add(new Field("sm", rst.getString("sm"), Field.Store.YES, Field.Index.TOKENIZED));
doc.add(new Field("id", rst.getString("id"), Field.Store.YES, Field.Index.TOKENIZED));
doc.add(new Field("dj", rst.getString("dj"), Field.Store.YES, Field.Index.TOKENIZED));
doc.add(new Field("fl", rst.getString("fl"), Field.Store.YES, Field.Index.TOKENIZED));
doc.add(new Field("bb", rst.getString("bb"), Field.Store.YES, Field.Index.TOKENIZED));
doc.add(new Field("bbbh", rst.getString("bbbh"), Field.Store.YES, Field.Index.TOKENIZED));
doc.add(new Field("flbh", rst.getString("flbh"), Field.Store.YES, Field.Index.TOKENIZED));
writer.addDocument(doc);
}
rst.close();
writer.optimize();
writer.close();
是Tomcat锁定文件 的问题
红色的两行是我后加的,以为加上之后,就可以了,但还是不行
不知道如何解决??