开发者

how to delete documents using term in lucene

开发者 https://www.devze.com 2023-01-22 01:04 出处:网络
I am trying to delete a document by using a term in lucene index. but the code that I made below isn\'t working. are there any suggestion of how can I perf开发者_开发百科orm deleting function in lucen

I am trying to delete a document by using a term in lucene index. but the code that I made below isn't working. are there any suggestion of how can I perf开发者_开发百科orm deleting function 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();        
}
}


IndexReader indexReader = IndexReader.open(directory); // this one uses default readonly mode

instead use this:

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

So you do not need any extra tool for deleting index contents. . .

0

精彩评论

暂无评论...
验证码 换一张
取 消