全文检索lucene学习笔记(二)

删除索引
package com.lucene.index;

import java.io.IOException;

import org.apache.lucene.index.CorruptIndexException;
import org.apache.lucene.index.IndexReader;

public class IndexDeleter {

	public static void main(String[] args) throws CorruptIndexException, IOException {
		
		IndexReader reader = IndexReader.open("C://test//index");
		
		System.out.println(reader.maxDoc());
		System.out.println(reader.numDocs());
		System.out.println(reader.isDeleted(1));
		
		reader.deleteDocument(1);
		
		System.out.println(reader.maxDoc());
		System.out.println(reader.numDocs());
		System.out.println(reader.isDeleted(1));
		System.out.println(reader.hasDeletions());
		
		reader.undeleteAll();
		reader.flush();
		reader.close();
	}
}
package com.lucene.index;

import java.io.IOException;

import org.apache.lucene.index.CorruptIndexException;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.Term;

public class IndexDeleter {

	public static void main(String[] args) throws CorruptIndexException, IOException {
		
		IndexReader reader = IndexReader.open("C://test//index");

		Term term = new Term("contents", "ERROR".toLowerCase());
		reader.deleteDocuments(term);
		
		reader.flush();
		reader.close();
	}
}

你可能感兴趣的:(c,String,Lucene,Class,全文检索)