2013-07-08 19 views
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文件做

回答

0

你似乎有評論指出,添加IndexItem.ID場到文檔就行了。如果該字段未添加到文檔中,則對deleteDocuments的調用將不會在該字段中找到任何匹配項,也不會刪除任何內容。

+0

對不起,這是我的打字錯誤,錯誤已得到解決。謝謝您的迴應。 –

+0

@myk。你是如何解決它的?我有一個類似的問題。 –