LuceneIndexDeleteId.java
上传用户:cctqzzy
上传日期:2022-03-14
资源大小:12198k
文件大小:1k
源码类别:

搜索引擎

开发平台:

Java

  1. package chapter5;
  2. import java.io.File;
  3. import java.io.IOException;
  4. import org.apache.lucene.index.Term;
  5. import org.apache.lucene.index.IndexReader;
  6. import org.apache.lucene.index.IndexWriter;
  7. import org.apache.lucene.analysis.Analyzer;
  8. import org.apache.lucene.analysis.SimpleAnalyzer;
  9. public class LuceneIndexDeleteId {
  10. public static void main(String[] args) {
  11. try {
  12. File indexDir = new File("D:\workshop\TextIndex"); 
  13. IndexReader reader = IndexReader.open(indexDir);            
  14. System.out.print("Next  Document ID  before delete: ");
  15. System.out.println(reader.maxDoc());
  16. System.out.print("Total Document Num before delete: ");
  17. System.out.println(reader.numDocs());
  18. reader.deleteDocument(0);
  19. System.out.print("Next  Document ID  after delete: ");
  20. System.out.println(reader.maxDoc());
  21. System.out.print("Total Document Num after delete: ");
  22. System.out.println(reader.numDocs());
  23. reader.undeleteAll();
  24. System.out.print("Next  Document ID  after undelete: ");
  25. System.out.println(reader.maxDoc());
  26. System.out.print("Total Document Num after undelete: ");
  27. System.out.println(reader.numDocs());
  28. reader.close();
  29. }catch (IOException e) {
  30. e.printStackTrace();
  31. }
  32. }
  33. }