本文整理汇总了C++中BooleanQuery::rewrite方法的典型用法代码示例。如果您正苦于以下问题:C++ BooleanQuery::rewrite方法的具体用法?C++ BooleanQuery::rewrite怎么用?C++ BooleanQuery::rewrite使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BooleanQuery
的用法示例。
在下文中一共展示了BooleanQuery::rewrite方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testExtractFromBooleanQuery
void testExtractFromBooleanQuery( CuTest * tc )
{
Directory * pIndex = setUpIndex();
IndexReader * pReader = IndexReader::open( pIndex );
TermSet termSet;
Term * t1 = _CLNEW Term( _T("data"), _T("aaaab") );
Term * t2 = _CLNEW Term( _T("data"), _T("aaabb") );
Term * t3 = _CLNEW Term( _T("data"), _T("aaabb") );
BooleanQuery * bq = _CLNEW BooleanQuery();
bq->add( _CLNEW TermQuery( t1 ), true, BooleanClause::SHOULD );
bq->add( _CLNEW TermQuery( t2 ), true, BooleanClause::SHOULD );
bq->add( _CLNEW TermQuery( t3 ), true, BooleanClause::SHOULD );
Query * rewrite = bq->rewrite( pReader );
rewrite->extractTerms( &termSet );
assertEqualsMsg( _T( "wrong number of terms" ), 2, termSet.size() );
for( TermSet::iterator itTerms = termSet.begin(); itTerms != termSet.end(); itTerms++ )
{
Term * pTerm = *itTerms;
assertTrueMsg( _T( "wrong term" ), ( 0 == t1->compareTo( pTerm ) || 0 == t2->compareTo( pTerm )));
}
clearTermSet( termSet );
_CLLDECDELETE( t1 );
_CLLDECDELETE( t2 );
_CLLDECDELETE( t3 );
if( rewrite != bq )
_CLDELETE( rewrite );
_CLDELETE( bq );
pReader->close();
_CLDELETE( pReader );
closeIndex( pIndex );
pIndex = NULL;
}
示例2: testBooleanPrefixQuery
/// TestBooleanPrefixQuery.java, ported 5/9/2009
void testBooleanPrefixQuery(CuTest* tc) {
RAMDirectory directory;
WhitespaceAnalyzer a;
TCHAR* categories[] = {_T("food"), _T("foodanddrink"),
_T("foodanddrinkandgoodtimes"), _T("food and drink"), NULL};
Query* rw1 = NULL;
Query* rw2 = NULL;
try {
IndexWriter* writer = _CLNEW IndexWriter(&directory, &a, true);
for (size_t i = 0; categories[i]!=NULL; i++) {
Document* doc = new Document();
doc->add(*_CLNEW Field(_T("category"), categories[i], Field::STORE_YES | Field::INDEX_UNTOKENIZED));
writer->addDocument(doc);
_CLLDELETE(doc);
}
writer->close();
_CLLDELETE(writer);
IndexReader* reader = IndexReader::open(&directory);
Term* t = _CLNEW Term(_T("category"), _T("foo"));
PrefixQuery* query = _CLNEW PrefixQuery(t);
_CLDECDELETE(t);
rw1 = query->rewrite(reader);
BooleanQuery* bq = _CLNEW BooleanQuery();
bq->add(query, true, BooleanClause::MUST);
rw2 = bq->rewrite(reader);
reader->close(); // TODO: check necessity (_CLLDELETE(reader) alone will not do the same cleanup)
_CLLDELETE(reader);
_CLLDELETE(bq);
} catch (CLuceneError& e) {
CuFail(tc, e.twhat());
}
BooleanQuery* bq1 = NULL;
if (rw1->instanceOf(BooleanQuery::getClassName())) {
bq1 = (BooleanQuery*) rw1;
}
BooleanQuery* bq2 = NULL;
if (rw2->instanceOf(BooleanQuery::getClassName())) {
bq2 = (BooleanQuery*) rw2;
} else {
CuFail(tc, _T("Rewrite"));
}
bool bClausesMatch = bq1->getClauseCount() == bq2->getClauseCount();
_CLLDELETE(rw1);
_CLLDELETE(rw2);
if (!bClausesMatch) {
CuFail(tc, _T("Number of Clauses Mismatch"));
}
}