How to delete documents using the term in lucene

I am trying to delete a document using the term in the lucene index. but the code I made below does not work. is there any suggestion on how i can perform function removal in lucene index?

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();        
}
}
+3
source share
1 answer
IndexReader indexReader = IndexReader.open(directory); // this one uses default readonly mode

use this instead:

IndexReader indexReader = IndexReader.open(directory, false); // this will open the index in edit mode and you can delete the index. . . 

Therefore, you do not need an additional tool to remove the contents of the index.,.

+2
source

Source: https://habr.com/ru/post/1771265/


All Articles