- Lucene 4 Cookbook
- Edwood Ng Vineeth Mohan
- 231字
- 2021-07-16 14:07:48
Deleting documents
We have learned how documents are added to an index. Now, we will see how to delete Documents. Suppose you want to keep your index up to date by deleting documents that are a week old. All of a sudden, the ability to remove documents becomes a very important feature. Let's see how can we do that.
How to do it...
IndexWriter provides the interface to delete documents from an index. It takes either term or query as argument, and will delete all the documents matching these arguments:
deleteDocuments(Term)
deleteDocuments(Term… terms)
deleteDocuments(Query)
deleteDocuments(Query… queries)
deleteAll( )
Here is a code snippet on how deleteDocuments
is called:
indexWriter.deleteDocuments(new Term("id", "1"));")); indexWriter.close();
How it works…
Assuming IndexWriter is already instantiated, this code will trigger IndexWriter to delete all the documents that contain the term id
where the value equals 1. Then, we call close to commit changes and close the IndexWriting. Note that this is a match to a Field called id; it's not the same as DocId.
In fact, deletions do not happen at once. They are kept in the memory buffer and later flushed to the directory. The documents are initially marked as deleted on disk so subsequent searches will simply skip the deleted documents; however, to free the memory, you still need to wait. We will see the underlying process in detail in due course.
- 自己動手寫搜索引擎
- 數據庫程序員面試筆試真題與解析
- 算法精粹:經典計算機科學問題的Java實現
- DevOps Automation Cookbook
- OpenCV 4計算機視覺項目實戰(原書第2版)
- scikit-learn Cookbook(Second Edition)
- 邊玩邊學Scratch3.0少兒趣味編程
- Learning Unreal Engine Game Development
- 大學計算機應用基礎(Windows 7+Office 2010)(IC3)
- Mastering ASP.NET Core 2.0
- 3D Printing Designs:Octopus Pencil Holder
- SQL Server實例教程(2008版)
- Elastix Unified Communications Server Cookbook
- 第五空間戰略:大國間的網絡博弈
- C語言從入門到精通(微視頻精編版)