0
我有一種方法可以從我的Lucene索引中搜索和刪除文檔。Lucene IndexReader提交不起作用
但是,當我運行代碼兩次時,它仍然找到標記爲從先前的迭代中刪除的文檔,並且indexReader.hasDeletions()評估爲true。
public void duplicatesRemover(String currentIndex) throws Exception {
Directory directory = FSDirectory.open(new File(currentIndex));
IndexReader indexReader = IndexReader.open(directory, false);
IndexSearcher indexSearcher = new IndexSearcher(indexReader);
int dups = 0;
for (int i = 0; i < indexReader.numDocs(); i++) {
Document doc = indexReader.document(i);
int articleId = Integer.parseInt(doc.get("articleId"));
Query q = NumericRangeQuery.newIntRange("articleId", articleId, articleId, true, true);
TopDocs topDocs = indexSearcher.search(q, 10);
if (topDocs.totalHits > 1) {
indexReader.deleteDocument(i);
System.out.print("Total matches from search found: " + topDocs.totalHits + " articleId = " + articleId);
System.out.println(" total dups found " + ++dups + "/" + i);
}
}
if(indexReader.hasDeletions()){
System.out.println("Has deletions");
Map<String, String> commitUserData = new HashMap<String, String>();
commitUserData.put("foo", "fighter");
indexReader.commit(commitUserData);
}
indexSearcher.close();
indexReader.close();
directory.close();
}
非常感謝什麼Lucene的版本,您使用的瑜伽士
使用最熱門的標籤來描述您正在使用的技術/語言。這將幫助人們找到你的問題並回答它。 – Artemix