- 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.
- 數(shù)據(jù)庫原理及應(yīng)用(Access版)第3版
- C語言最佳實(shí)踐
- Mastering C# Concurrency
- Mastering Unity Shaders and Effects
- Python應(yīng)用輕松入門
- Mastering macOS Programming
- Visual Basic程序設(shè)計(jì)實(shí)驗(yàn)指導(dǎo)(第4版)
- Python數(shù)據(jù)分析從0到1
- 精通Python設(shè)計(jì)模式(第2版)
- 網(wǎng)站構(gòu)建技術(shù)
- C#應(yīng)用程序設(shè)計(jì)教程
- Haskell Data Analysis Cookbook
- Android應(yīng)用開發(fā)深入學(xué)習(xí)實(shí)錄
- Django 5企業(yè)級(jí)Web應(yīng)用開發(fā)實(shí)戰(zhàn)(視頻教學(xué)版)
- Python商務(wù)數(shù)據(jù)分析(微課版)