本文整理汇总了C++中IndexReader::close方法的典型用法代码示例。如果您正苦于以下问题:C++ IndexReader::close方法的具体用法?C++ IndexReader::close怎么用?C++ IndexReader::close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IndexReader
的用法示例。
在下文中一共展示了IndexReader::close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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 );
}
示例2: 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 );
}
示例3: 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);
}
示例4: 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);
}
示例5: while
_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);
}
示例6: 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;
}
示例7: 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 );
}
示例8: 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);
}
示例9: closeReaders
void SegmentMerger::closeReaders()
{
for (uint32_t i = 0; i < readers.size(); i++) {
// close readers
IndexReader* reader = readers[i];
reader->close();
}
}
示例10: SearchFilesC
void SearchFilesC(const char* index, const char* fobizzle){
standard::StandardAnalyzer analyzer;
char line[80];
TCHAR tline[80];
TCHAR* buf;
IndexReader* reader = IndexReader::open(index);
//printf("Enter query string: ");
strncpy(line,fobizzle,80);
//line[strlen(line)-1]=0;
IndexReader* newreader = reader->reopen();
if ( newreader != reader ){
_CLLDELETE(reader);
reader = newreader;
}
IndexSearcher s(reader);
STRCPY_AtoT(tline,line,80);
Query* q = QueryParser::parse(tline,_T("contents"),&analyzer);
buf = q->toString(_T("contents"));
_tprintf(_T("Searching for: %S\n\n"), buf);
_CLDELETE_LCARRAY(buf);
uint64_t str = Misc::currentTimeMillis();
Hits* h = s.search(q);
uint32_t srch = (int32_t)(Misc::currentTimeMillis() - str);
str = Misc::currentTimeMillis();
//SearchData search[h->length()];
for ( size_t i=0; i < h->length(); i++ ){
Document* doc = &h->doc(i);
//const TCHAR* buf = doc.get(_T("contents"));
_tprintf(_T("%d. %S - %f\n"), i, doc->get(_T("path")), h->score(i));
//search[i].set_path(doc->get(_T("path")));
}
printf("\n\nSearch took: %d ms.\n", srch);
printf("Screen dump took: %d ms.\n\n", (int32_t)(Misc::currentTimeMillis() - str));
_CLLDELETE(h);
_CLLDELETE(q);
s.close();
reader->close();
_CLLDELETE(reader);
};
示例11: verifyTermDocs
static void verifyTermDocs(CuTest *tc, Directory * dir, Term * term, int numDocs) {
IndexReader * reader = IndexReader::open(dir);
TermDocs * termDocs = reader->termDocs(term);
int count = 0;
while (termDocs->next())
count++;
assertEquals(numDocs, count);
termDocs->close();
_CLLDELETE(termDocs);
reader->close();
_CLLDELETE(reader);
}
示例12: testMergeAfterCopy
// case 4: tail segments, invariants hold, copy, invariants not hold
void testMergeAfterCopy(CuTest * tc) {
// main directory
Directory * dir = _CLNEW RAMDirectory();
// auxiliary directory
Directory * aux = _CLNEW RAMDirectory();
WhitespaceAnalyzer an;
setUpDirs(tc, dir, aux);
IndexReader * reader = IndexReader::open(aux);
for (int i = 0; i < 20; i++) {
reader->deleteDocument(i);
}
assertEquals(10, reader->numDocs());
reader->close();
_CLLDELETE(reader);
IndexWriter4Test * writer = newWriter(dir, &an, false);
writer->setMaxBufferedDocs(4);
writer->setMergeFactor(4);
ValueArray<Directory*> dirs(2);
dirs[0] = aux;
dirs[1] = aux;
writer->addIndexesNoOptimize(dirs);
assertEquals(1020, writer->docCount());
assertEquals(1000, writer->getDocCount(0));
writer->close();
_CLLDELETE(writer);
// make sure the index is correct
verifyNumDocs(tc, dir, 1020);
dir->close();
_CLLDELETE(dir);
aux->close();
_CLLDELETE(aux);
}
示例13: testBooleanOrderUnAffected
void testBooleanOrderUnAffected()
{
// NOTE: uses index build in *this* setUp
IndexReader * pReader = IndexReader::open( m_pSmall );
IndexSearcher * pSearch = _CLNEW IndexSearcher( pReader );
// first do a regular RangeQuery which uses term expansion so
// docs with more terms in range get higher scores
Term * pLower = _CLNEW Term( _T( "data" ), _T( "1" ));
Term * pUpper = _CLNEW Term( _T( "data" ), _T( "4" ));
Query * rq = _CLNEW RangeQuery( pLower, pUpper, true );
_CLLDECDELETE( pUpper );
_CLLDECDELETE( pLower );
Hits * pExpected = pSearch->search( rq );
size_t numHits = pExpected->length();
// now do a boolean where which also contains a
// ConstantScoreRangeQuery and make sure the order is the same
BooleanQuery * q = _CLNEW BooleanQuery();
q->add( rq, true, BooleanClause::MUST );
q->add( csrq( _T( "data" ), _T( "1" ), _T( "6" ), true, true ), true, BooleanClause::MUST );
Hits * pActual = pSearch->search( q );
assertEqualsMsg( _T( "wrong number of hits" ), numHits, pActual->length() );
for( size_t i = 0; i < numHits; i++ )
{
assertEqualsMsg( _T( "mismatch in docid for a hit" ), pExpected->id( i ), pActual->id( i ));
}
_CLDELETE( pActual );
_CLDELETE( pExpected );
_CLDELETE( q );
pSearch->close();
_CLDELETE( pSearch );
pReader->close();
_CLDELETE( pReader );
}
示例14: testExtractFromFuzzyQuery
void testExtractFromFuzzyQuery( CuTest * tc )
{
Directory * pIndex = setUpIndex();
IndexReader * pReader = IndexReader::open( pIndex );
TermSet termSet;
FuzzyQuery * fuzzy;
Term * t1;
Query * rewrite;
t1 = _CLNEW Term( _T("data"), _T("aaaab") );
fuzzy = _CLNEW FuzzyQuery( t1, 0.7f );
rewrite = fuzzy->rewrite( pReader );
rewrite->extractTerms( &termSet );
_CLLDECDELETE( t1 );
assertEqualsMsg( _T( "wrong number of terms" ), 4, 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( "aaabb" ), pTerm->text())
&& 0 != _tcscmp( _T( "aaaac" ), pTerm->text()))
{
assertTrueMsg( _T( "wrong term" ), false );
}
}
clearTermSet( termSet );
if( rewrite != fuzzy )
_CLDELETE( rewrite );
_CLDELETE( fuzzy );
pReader->close();
_CLDELETE( pReader );
closeIndex( pIndex );
pIndex = NULL;
}
示例15: testExtractFromTermQuery
void testExtractFromTermQuery( CuTest * tc )
{
Directory * pIndex = setUpIndex();
IndexReader * pReader = IndexReader::open( pIndex );
TermSet termSet;
Term * t1 = _CLNEW Term( _T("data"), _T("aaaaa") );
Term * t2 = _CLNEW Term( _T("data"), _T("bbbbb") );
Query * q1 = _CLNEW TermQuery( t1 );
Query * q2 = _CLNEW TermQuery( t2 );
Query * rewrite1 = q1->rewrite( pReader );
Query * rewrite2 = q2->rewrite( pReader );
rewrite1->extractTerms( &termSet );
assertEqualsMsg( _T( "wrong number of terms" ), 1, termSet.size() );
assertEqualsMsg( _T( "wrong term" ), 0, t1->compareTo( *(termSet.begin())) );
clearTermSet( termSet );
rewrite2->extractTerms( &termSet );
assertEqualsMsg( _T( "wrong number of terms" ), 1, termSet.size() );
assertEqualsMsg( _T( "wrong term" ), 0, t2->compareTo( *(termSet.begin())) );
clearTermSet( termSet );
_CLLDECDELETE( t1 );
_CLLDECDELETE( t2 );
if( q1 != rewrite1 )
_CLDELETE( rewrite1 );
_CLDELETE( q1 );
if( q2 != rewrite2 )
_CLDELETE( rewrite2 );
_CLDELETE( q2 );
pReader->close();
_CLDELETE( pReader );
closeIndex( pIndex );
pIndex = NULL;
}