void testSrchWildcard(CuTest *tc ){ #ifdef NO_WILDCARD_QUERY CuNotImpl(tc,_T("Wildcard")); #else CuAssert(tc,_T("Searcher was not open"),s!=NULL); //testWildcard _TestSearchesRun(tc, &a,s, _T("term*") ); _TestSearchesRun(tc, &a,s, _T("term*^2") ); _TestSearchesRun(tc, &a,s, _T("term~") ); _TestSearchesRun(tc, &a,s, _T("term^2~") ); _TestSearchesRun(tc, &a,s, _T("term~^2") ); _TestSearchesRun(tc, &a,s, _T("term*germ") ); _TestSearchesRun(tc, &a,s, _T("term*germ^3") ); //test problem reported by Gary Mangum BooleanQuery* bq = _CLNEW BooleanQuery(); Term* upper = _CLNEW Term(_T("contents"),_T("0105")); Term* lower = _CLNEW Term(_T("contents"),_T("0105")); RangeQuery* rq=_CLNEW RangeQuery(lower,upper,true); bq->add(rq,true,true,false); _CLDECDELETE(upper); _CLDECDELETE(lower); Term* prefix = _CLNEW Term(_T("contents"),_T("reuters21578")); PrefixQuery* pq = _CLNEW PrefixQuery(prefix); _CLDECDELETE(prefix); bq->add(pq,true,true,false); Hits* h = NULL; try{ h = s->search( bq ); }_CLFINALLY( _CLDELETE(h); _CLDELETE(bq); );
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 ); }
void RangeQuery::clear() { deleteTree(root); root = NULL; RangeQuery(); }
Query* RangeQuery::clone() const{ return _CLNEW RangeQuery(*this); }