1
public void index(IndexItem indexItem) throws IOException {
writer.deleteDocuments(new Term(IndexItem.ID,indexItem.getId().toString()));
Document doc = new Document();
// doc.add(new LongField(IndexItem.ID, indexItem.getId(), Field.Store.YES));
doc.add(new TextField(IndexItem.CONTENT, indexItem.getContent(), Field.Store.NO));
doc.add(new StringField(IndexItem.PATH, indexItem.getPath(), Field.Store.YES));
// add the document to the index
writer.addDocument(doc, analyzer);
writer.updateDocument(new Term(IndexItem.CONTENT, indexItem.getContent().toString()), doc);
System.out.println(indexItem.getTitle());
writer.close();
}
這裏Writer.deleteDocuments不起作用。因此,每次我索引一個文件,它都不會刪除已經存在的文件,然後創建一個新文件,而只是複製它。IndexWriter deleteDocuments函數不起作用
這是任何有work.lock文件做
對不起,這是我的打字錯誤,錯誤已得到解決。謝謝您的迴應。 –
@myk。你是如何解決它的?我有一個類似的問題。 –