[英]IndexWriter deleteDocuments function is not working
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();
}
Here Writer.deleteDocuments is not working. 这里Writer.deleteDocuments无法正常工作。 Thus each time I index a file, it doest not deletes already existing file then create a new one rather it just makes a copy of it. 因此,每次我索引一个文件时,它都不会删除现有文件,而是创建一个新文件,而只是制作一个副本。
Is this anything have to do with work.lock file 这与work.lock文件有关吗
You appear to have commented out the line that adds the IndexItem.ID
field to the document. 您似乎已注释掉将IndexItem.ID
字段添加到文档的行。 If that field isn't added to the document, then the call to deleteDocuments
won't find any matches on that field, and nothing will be deleted. 如果该字段未添加到文档中,则对deleteDocuments
的调用将在该字段上找不到任何匹配项,并且不会删除任何内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.