您的位置:首页 > 其它

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

2008-06-03 12:32 330 查看
删除索引
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();
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: