本文整理汇总了C++中Query::extractTerms方法的典型用法代码示例。如果您正苦于以下问题:C++ Query::extractTerms方法的具体用法?C++ Query::extractTerms怎么用?C++ Query::extractTerms使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Query
的用法示例。
在下文中一共展示了Query::extractTerms方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: 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;
}