![](/img/trans.png)
[英]Lucene - Update documents using LongPoint Field as Term in writer.updateDocuments()
[英]how to delete documents using term in lucene
我試圖通過使用lucene索引中的術語來刪除文檔。 但我下面的代碼不起作用。 有什么建議我怎樣才能在lucene索引中執行刪除功能?
public class DocumentDelete {
public static void main(String[] args) {
File indexDir = new File("C:/Users/Raden/Documents/lucene/LuceneHibernate/adi");
Term term = new Term(FIELD_PATH, "compatible");
Directory directory = FSDirectory.getDirectory(indexDir);
IndexReader indexReader = IndexReader.open(directory);
indexReader.deleteDocuments(term);
indexReader.close();
}
}
IndexReader indexReader = IndexReader.open(directory); // this one uses default readonly mode
改為使用這個:
IndexReader indexReader = IndexReader.open(directory, false); // this will open the index in edit mode and you can delete the index. . .
因此,您不需要任何額外的工具來刪除索引內容。 。 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.