您的位置:首页 > 编程语言 > C语言/C++

clucene-core-0.9.21b/src/demo DeleteFiles.cpp分析

2009-04-25 22:27 369 查看
#include "stdafx.h"

#include "CLucene.h"
#include <iostream>

using namespace std;
using namespace lucene::index;
using namespace lucene::util;
using namespace lucene::store;
using namespace lucene::document;

void DeleteFiles(const char* dir) {
IndexReader* reader = IndexReader::open(dir);  //打开目录

int32_t count = 0;
for (int32_t i = 0; i < reader->maxDoc(); i++){//遍历所有文档,并删除
reader->deleteDocument (i);
count ++;
}
printf("Deleted %d files/n", count);//输出删除的文件数
reader->close();    //关闭,释放 以后这2步要记住
_CLDELETE(reader);

//OPTIMIZE
//优化
if ( IndexReader::indexExists(dir) ){//检测指定目录是否存在
lucene::analysis::SimpleAnalyzer an;
if ( IndexReader::isLocked(dir) ){//解除锁
printf("Index was locked... unlocking it./n");
IndexReader::unlock(dir);
}

IndexWriter* writer = _CLNEW IndexWriter( dir, &an, false);// //索引重排
writer->optimize();
_CLDELETE(writer);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: