#include "stdafx.h" #include "CLucene.h" #include "CLucene/index/Term.h" #include "CLucene/index/SegmentTermEnum.h" #include <iostream> using namespace std; using namespace lucene::analysis; using namespace lucene::index; using namespace lucene::util; using namespace lucene::search; //获得Max Docs,Num Docs,Current Version,Term count void getStats(const char* directory){ IndexReader* r = IndexReader::open(directory); _tprintf(_T("Statistics for %s/n"), directory); printf("==================================/n"); printf("Max Docs: %d/n", r->maxDoc() ); printf("Num Docs: %d/n", r->numDocs() ); int64_t ver = r->getCurrentVersion(directory); TCHAR str[16]; _i64tot(ver, str, 10); _tprintf(_T("Current Version: %s/n"), str ); //读取项 TermEnum* te = r->terms(); int32_t nterms; for (nterms = 0; te->next() == true; nterms++) {//这里可以操作 /* empty */ } printf("Term count: %d/n/n", nterms ); _CLDELETE(te); r->close(); _CLDELETE(r); }