本文整理汇总了C++中IndexReader类的典型用法代码示例。如果您正苦于以下问题:C++ IndexReader类的具体用法?C++ IndexReader怎么用?C++ IndexReader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IndexReader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: QStringList
QStringList ZefaniaLex::getAllKeys()
{
try {
if(!hasIndex()) {
if(buildIndex() != 0) {
return QStringList();
}
}
const QString index = indexPath();
IndexReader* reader = IndexReader::open(index.toStdString().c_str());
QStringList ret;
for(int i = 0; i < reader->numDocs(); i++) {
Document doc;
reader->document(i, doc);
#ifdef OBV_USE_WSTRING
ret.append(QString::fromWCharArray(doc.get(_T("key"))));
#else
ret.append(QString::fromUtf16((const ushort*)doc.get(_T("key"))));
#endif
}
return ret;
}
catch(...)
{
return QStringList();
}
}
示例2: createIndex
void createIndex(CuTest* tc, Directory* dir, bool multiSegment) {
WhitespaceAnalyzer whitespaceAnalyzer;
IndexWriter w(dir, &whitespaceAnalyzer, true);
w.setMergePolicy(_CLNEW LogDocMergePolicy());
Document doc;
for (int i = 0; i < 100; i++) {
createDocument(doc, i, 4);
w.addDocument(&doc);
if (multiSegment && (i % 10) == 0) {
w.flush();
}
}
if (!multiSegment) {
w.optimize();
}
w.close();
IndexReader* r = IndexReader::open(dir);
if (multiSegment) {
CuAssert(tc,_T("check is multi"), strcmp(r->getObjectName(),"MultiSegmentReader")==0);
} else {
CuAssert(tc,_T("check is segment"), strcmp(r->getObjectName(),"SegmentReader")==0);
}
r->close();
_CLDELETE(r);
}
示例3: assertEquals
/**
* Verifies that the index has the correct number of documents.
*/
void TestSpansAdvanced2::testVerifyIndex()
{
IndexReader * reader = IndexReader::open( directory );
assertEquals( 8, reader->numDocs() );
reader->close();
_CLDELETE( reader );
}
示例4: testEqualScores
void testEqualScores()
{
// NOTE: uses index build in *this* setUp
IndexReader * pReader = IndexReader::open( m_pSmall );
IndexSearcher * pSearch = _CLNEW IndexSearcher( pReader );
Hits * pResult;
// some hits match more terms then others, score should be the same
Query * q = csrq( _T( "data" ), _T( "1" ), _T( "6" ), true, true );
pResult = pSearch->search( q );
size_t numHits = pResult->length();
assertEqualsMsg( _T( "wrong number of results" ), 6, numHits );
float_t score = pResult->score( 0 );
for( size_t i = 1; i < numHits; i++ )
{
assertTrueMsg( _T( "score was not the same" ), score == pResult->score( i ));
}
_CLDELETE( pResult );
_CLDELETE( q );
pSearch->close();
_CLDELETE( pSearch );
pReader->close();
_CLDELETE( pReader );
}
示例5: listFields
int
listFields(int argc, char** argv) {
// parse arguments
parseArguments(argc, argv);
string backend = options['t'];
string indexdir = options['d'];
// check arguments: indexdir
if (indexdir.length() == 0) {
pe("Provide the directory with the index.\n");
return usage(argc, argv);
}
// create an index manager
IndexManager* manager = getIndexManager(backend, indexdir);
if (manager == 0) {
return usage(argc, argv);
}
IndexReader* reader = manager->indexReader();
vector<string> fields = reader->fieldNames();
vector<string>::const_iterator i;
for (i=fields.begin(); i!=fields.end(); ++i) {
printf("%s\n", i->c_str());
}
IndexPluginLoader::deleteIndexManager(manager);
return 0;
}
示例6: QStringList
QStringList ZefaniaLex::getAllKeys()
{
if(!m_entryList.isEmpty()) {
return m_entryList;
}
try {
if(!hasIndex()) {
if(buildIndex() != 0) {
return QStringList();
}
}
const QString index = indexPath();
IndexReader* reader = IndexReader::open(index.toStdString().c_str());
QStringList ret;
for(int i = 0; i < reader->numDocs(); i++) {
Document doc;
reader->document(i, doc);
ret.append(SearchTools::toQString(doc.get(_T("key"))));
}
m_entryList = ret;
return ret;
}
catch(CLuceneError &err) {
myWarning() << "clucene error = " << err.what();
return QStringList();
}
catch(...) {
return QStringList();
}
}
示例7: initFullIndex
/**
* 初始化 全量index
*
* @param path 数据存放路径
*
* @return 0: success ; -1: 程序处理失败
*/
int initFullIndex(const char * path)
{
IndexReader * reader = IndexReader::getInstance();
if ( NULL == reader )
{
TERR("IndexReader instance is null");
return -1;
}
if ( (NULL == path) || strlen( path ) <= 0 )
{
TERR("index node's path attribute is null");
return -1;
}
TLOG("begin to load full index! path:%s", path);
if ( reader->open( path ) < 0)
{
TERR("load full index failed! path:%s", path);
return -1;
}
TLOG("load full index success!");
return 0;
}
示例8: main
int main()
{
Parser p;
IndexReader in;
in.genIndexFromFile();
Search s;
string query;
while (getline(cin,query)) {
Query* q=p.parse(query);
//cout<<"------"<<endl;
//cout<<q->sign<<" "<<q->token<<endl;
/*for(int i=0;i<q->size();i++)
{
Query* s=q->get(i);
//cout<<s->sign<<" "<<s->token<<endl;
for(int j=0;j<s->size();j++)
{
Query* p=s->get(j);
// cout<<p->sign<<" "<<p->token<<endl;
}
}*/
vector<vector<string> > l;
s.search(q,in,l);
s.show(q,in,l);
delete q;
}
}
示例9: checkDir
// BK> all test functions are the same except RAMDirectory constructor, so shared code moved here
void checkDir(CuTest *tc, MockRAMDirectory * ramDir) {
// Check size
CuAssertTrue(tc, ramDir->sizeInBytes == ramDir->getRecomputedSizeInBytes(), _T("RAMDir size"));
// open reader to test document count
IndexReader * reader = IndexReader::open(ramDir);
CuAssertEquals(tc, docsToAdd, reader->numDocs(), _T("document count"));
// open search to check if all doc's are there
IndexSearcher * searcher = _CLNEW IndexSearcher(reader);
// search for all documents
Document doc;
for (int i = 0; i < docsToAdd; i++) {
searcher->doc(i, doc);
CuAssertTrue(tc, doc.getField(_T("content")) != NULL, _T("content is NULL"));
}
// cleanup
reader->close();
searcher->close();
_CLLDELETE(reader);
_CLLDELETE(searcher);
}
示例10: _LUCENE_THREAD_FUNC
_LUCENE_THREAD_FUNC(atomicSearchTest, _directory){
Directory* directory = (Directory*)_directory;
uint64_t stopTime = Misc::currentTimeMillis() + 1000*ATOMIC_SEARCH_RUN_TIME_SEC;
int count = 0;
try {
while(Misc::currentTimeMillis() < stopTime && !atomicSearchFailed) {
IndexReader* r = IndexReader::open(directory);
try {
if ( 100 != r->numDocs() ){
fprintf(stderr, "err 2: 100 != %d \n", r->numDocs());
atomicSearchFailed = true;
}
} catch (CLuceneError& e) {
fprintf(stderr, "err 3: %d:%s\n", e.number(), e.what());
atomicSearchFailed = true;
break;
}
r->close();
_CLDELETE(r);
count++;
}
} catch (CLuceneError& e) {
fprintf(stderr, "err 4: #%d: %s\n", e.number(), e.what());
atomicSearchFailed = true;
}
_LUCENE_THREAD_FUNC_RETURN(0);
}
示例11: testBoost
void testBoost()
{
// NOTE: uses index build in *this* setUp
IndexReader * pReader = IndexReader::open( m_pSmall );
IndexSearcher * pSearch = _CLNEW IndexSearcher( pReader );
Hits * pResult;
// test for correct application of query normalization
// must use a non score normalizing method for this.
Query * q = csrq( _T( "data" ), _T( "1" ), _T( "6" ), true, true );
q->setBoost( 100 );
pResult = pSearch->search( q );
for( size_t i = 1; i < pResult->length(); i++ )
{
assertTrueMsg( _T( "score was not was not correct" ), 1.0f == pResult->score( i ));
}
_CLDELETE( pResult );
_CLDELETE( q );
//
// Ensure that boosting works to score one clause of a query higher
// than another.
//
Query * q1 = csrq( _T( "data" ), _T( "A" ), _T( "A" ), true, true ); // matches document #0
q1->setBoost( .1f );
Query * q2 = csrq( _T( "data" ), _T( "Z" ), _T( "Z" ), true, true ); // matches document #1
BooleanQuery * bq = _CLNEW BooleanQuery( true );
bq->add( q1, true, BooleanClause::SHOULD );
bq->add( q2, true, BooleanClause::SHOULD );
pResult = pSearch->search( bq );
assertEquals( 1, pResult->id( 0 ));
assertEquals( 0, pResult->id( 1 ));
assertTrue( pResult->score( 0 ) > pResult->score( 1 ));
_CLDELETE( pResult );
_CLDELETE( bq );
q1 = csrq( _T( "data" ), _T( "A" ), _T( "A" ), true, true ); // matches document #0
q1->setBoost( 10.0f );
q2 = csrq( _T( "data" ), _T( "Z" ), _T( "Z" ), true, true ); // matches document #1
bq = _CLNEW BooleanQuery( true );
bq->add( q1, true, BooleanClause::SHOULD );
bq->add( q2, true, BooleanClause::SHOULD );
pResult = pSearch->search( bq );
assertEquals( 0, pResult->id( 0 ));
assertEquals( 1, pResult->id( 1 ));
assertTrue( pResult->score( 0 ) > pResult->score( 1 ));
_CLDELETE( pResult );
_CLDELETE( bq );
pSearch->close();
_CLDELETE( pSearch );
pReader->close();
_CLDELETE( pReader );
}
示例12: testExtractFromWildcardQuery
void testExtractFromWildcardQuery( CuTest * tc )
{
Directory * pIndex = setUpIndex();
IndexReader * pReader = IndexReader::open( pIndex );
TermSet termSet;
WildcardQuery * wildcard;
Term * t1;
Query * rewrite;
t1 = _CLNEW Term( _T("data"), _T("aaaa?") );
wildcard = _CLNEW WildcardQuery( t1 );
rewrite = wildcard->rewrite( pReader );
rewrite->extractTerms( &termSet );
_CLLDECDELETE( t1 );
assertEqualsMsg( _T( "wrong number of terms" ), 3, termSet.size() );
for( TermSet::iterator itTerms = termSet.begin(); itTerms != termSet.end(); itTerms++ )
{
Term * pTerm = *itTerms;
if( 0 != _tcscmp( _T( "aaaaa" ), pTerm->text())
&& 0 != _tcscmp( _T( "aaaab" ), pTerm->text())
&& 0 != _tcscmp( _T( "aaaac" ), pTerm->text()))
{
assertTrueMsg( _T( "wrong term" ), false );
}
}
clearTermSet( termSet );
if( rewrite != wildcard )
_CLDELETE( rewrite );
_CLDELETE( wildcard );
t1 = _CLNEW Term( _T("data"), _T("aaa*") );
wildcard = _CLNEW WildcardQuery( t1 );
rewrite = wildcard->rewrite( pReader );
rewrite->extractTerms( &termSet );
_CLLDECDELETE( t1 );
assertEqualsMsg( _T( "wrong number of terms" ), 5, termSet.size() );
for( TermSet::iterator itTerms = termSet.begin(); itTerms != termSet.end(); itTerms++ )
{
Term * pTerm = *itTerms;
assertTrueMsg( _T( "wrong term" ), ( 0 == _tcsncmp( _T( "aaa" ), pTerm->text(), 3 )));
}
clearTermSet( termSet );
if( rewrite != wildcard )
_CLDELETE( rewrite );
_CLDELETE( wildcard );
pReader->close();
_CLDELETE( pReader );
closeIndex( pIndex );
pIndex = NULL;
}
示例13: verifyNumDocs
static void verifyNumDocs(CuTest *tc, Directory * dir, int numDocs) {
IndexReader * reader = IndexReader::open(dir);
assertEquals(numDocs, reader->maxDoc());
assertEquals(numDocs, reader->numDocs());
reader->close();
_CLLDELETE(reader);
}
示例14: closeReaders
void SegmentMerger::closeReaders()
{
for (uint32_t i = 0; i < readers.size(); i++) {
// close readers
IndexReader* reader = readers[i];
reader->close();
}
}
示例15: MinimumHeap
int
SmallFileIndex::init_data_source(void *init_para,
RecordReader **reader)
{
int ret = 0;
vector<plfs_pathback> &droppings = *(((index_init_para_t *)init_para)->namefiles);
list<index_mapping_t> *fid = ((index_init_para_t *)init_para)->fids;
MinimumHeap *min_heap = new MinimumHeap(fid->size(), index_compare_func);
mlog(SMF_DAPI, "Start to build index %p.", this);
if (fid->size() == 0) {
*reader = min_heap;
return 0;
}
unsigned int buf_size = get_read_buffer_size(fid->size());
list<index_mapping_t>::const_iterator itr;
for (itr = fid->begin(); itr != fid->end(); itr++ ) {
string index_fname;
IndexReader *indexfile;
int pop_result;
struct plfs_pathback entry;
entry.back = droppings[itr->second].back;
assert(itr->second < droppings.size());
ret = dropping_name2index(droppings[itr->second].bpath, entry.bpath);
if (ret) {
mlog(SMF_ERR, "Unable to get index file name from name file:%s.",
droppings[itr->second].bpath.c_str());
break;
}
indexfile = new IndexReader(entry, *itr, buf_size);
/* Only after this pop_front(), we can get the first record. */
pop_result = indexfile->pop_front();
if (pop_result == 1 && indexfile->front()) {
mlog(SMF_DAPI, "Load index entries from %s.", entry.bpath.c_str());
min_heap->push_back(indexfile);
} else if (pop_result == 0 || pop_result == -ENOENT) {
delete indexfile;
mlog(SMF_DAPI, "Skip empty or non-existent index file:%s.",
entry.bpath.c_str());
} else {
delete indexfile;
mlog(SMF_ERR, "Unable to read index entries from %s, err = %d!",
entry.bpath.c_str(), pop_result);
ret = pop_result;
break;
}
}
if (ret == 0) {
mlog(SMF_DAPI, "Successfully build index %p.", this);
*reader = min_heap;
} else {
delete min_heap;
mlog(SMF_DAPI, "Failed to build index %p. errno = %d.", this, ret);
}
return ret;
}