#include "stdafx.h"
#include "CLucene.h"
#ifdef _CLCOMPILER_MSVC
#ifdef _DEBUG
#define CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#endif
#endif
#include <iostream>
using namespace std;
//删除文件
void DeleteFiles(const char* dir);
//Index文件
//path 文件路径
//target 存放Index的路径
//clearIndex 是否清除Index
void IndexFiles(char* path, char* target, const bool clearIndex);
//
void SearchFiles(const char* index);
//获得Max Docs,Num Docs,Current Version,Term count 信息
void getStats(const char* directory);
int main( int32_t argc, char** argv ){
//Dumper Debug
//内存泄露用
#ifdef TR_LEAKS
#ifdef _CLCOMPILER_MSVC
#ifdef _DEBUG
_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );//| _CRTDBG_CHECK_ALWAYS_DF | _CRTDBG_CHECK_CRT_DF );
#endif
#endif
#endif
//获得开始时间 计时用
uint64_t str = lucene::util::Misc::currentTimeMillis();
try{
//从屏幕输入读入的目录
printf("Location of text files to be indexed: ");
char files[250];
fgets(files,250,stdin);
files[strlen(files)-1] = 0;
//从屏幕输入写入的目录
printf("Location to store the clucene index: ");
char ndx[250];
fgets(ndx,250,stdin);
ndx[strlen(ndx)-1] = 0;
//建立Index
IndexFiles(files,ndx,true);
//获得状态
getStats(ndx);
//搜索
SearchFiles(ndx);
//删除Index,Index重排
DeleteFiles(ndx);
}catch(CLuceneError& err){
printf(err.what());
}catch(...){
printf("Unknown error");
}
_lucene_shutdown(); //clears all static memory
//print lucenebase debug
#ifdef LUCENE_ENABLE_MEMLEAKTRACKING
lucene::debug::LuceneBase::__cl_PrintUnclosedObjects();
//clear memtracking memory (not the unclosed objects)
lucene::debug::LuceneBase::__cl_ClearMemory();
#endif
//Debuggin techniques:
//For msvc, use this for breaking on memory leaks:
// _crtBreakAlloc
//to break at this clucene item:
// _lucene_counter_break
//run a memory check before deleting objects:
// _lucene_run_objectcheck
//if LUCENE_ENABLE_CONSTRUCTOR_LOG is on, dont do log if this is true:
// _lucene_disable_debuglogging
//总共花时
printf ("/n/nTime taken: %d/n/n",lucene::util::Misc::currentTimeMillis() - str);
return 0;
}