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

 #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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值