本文整理汇总了C++中AndMatchExpression::add方法的典型用法代码示例。如果您正苦于以下问题:C++ AndMatchExpression::add方法的具体用法?C++ AndMatchExpression::add怎么用?C++ AndMatchExpression::add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AndMatchExpression
的用法示例。
在下文中一共展示了AndMatchExpression::add方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: BSON
TEST(AndOp, MatchesThreeClauses) {
BSONObj baseOperand1 = BSON("$gt" << 1);
BSONObj baseOperand2 = BSON("$lt" << 10);
BSONObj baseOperand3 = BSON("$lt" << 100);
unique_ptr<ComparisonMatchExpression> sub1(new GTMatchExpression());
ASSERT(sub1->init("a", baseOperand1["$gt"]).isOK());
unique_ptr<ComparisonMatchExpression> sub2(new LTMatchExpression());
ASSERT(sub2->init("a", baseOperand2["$lt"]).isOK());
unique_ptr<ComparisonMatchExpression> sub3(new LTMatchExpression());
ASSERT(sub3->init("b", baseOperand3["$lt"]).isOK());
AndMatchExpression andOp;
andOp.add(sub1.release());
andOp.add(sub2.release());
andOp.add(sub3.release());
ASSERT(andOp.matchesBSON(BSON("a" << 5 << "b" << 6), NULL));
ASSERT(!andOp.matchesBSON(BSON("a" << 5), NULL));
ASSERT(!andOp.matchesBSON(BSON("b" << 6), NULL));
ASSERT(!andOp.matchesBSON(BSON("a" << 1 << "b" << 6), NULL));
ASSERT(!andOp.matchesBSON(BSON("a" << 10 << "b" << 6), NULL));
}
示例2: logicalRewrite
// static
// XXX TODO: This does not belong here at all.
MatchExpression* CanonicalQuery::logicalRewrite(MatchExpression* tree) {
// Only thing we do is pull an OR up at the root.
if (MatchExpression::AND != tree->matchType()) {
return tree;
}
// We want to bail out ASAP if we have nothing to do here.
size_t numOrs = 0;
for (size_t i = 0; i < tree->numChildren(); ++i) {
if (MatchExpression::OR == tree->getChild(i)->matchType()) {
++numOrs;
}
}
// Only do this for one OR right now.
if (1 != numOrs) {
return tree;
}
// Detach the OR from the root.
invariant(NULL != tree->getChildVector());
std::vector<MatchExpression*>& rootChildren = *tree->getChildVector();
MatchExpression* orChild = NULL;
for (size_t i = 0; i < rootChildren.size(); ++i) {
if (MatchExpression::OR == rootChildren[i]->matchType()) {
orChild = rootChildren[i];
rootChildren.erase(rootChildren.begin() + i);
break;
}
}
// AND the existing root with each or child.
invariant(NULL != orChild);
invariant(NULL != orChild->getChildVector());
std::vector<MatchExpression*>& orChildren = *orChild->getChildVector();
for (size_t i = 0; i < orChildren.size(); ++i) {
AndMatchExpression* ama = new AndMatchExpression();
ama->add(orChildren[i]);
ama->add(tree->shallowClone());
orChildren[i] = ama;
}
delete tree;
// Clean up any consequences from this tomfoolery.
return normalizeTree(orChild);
}
示例3: TEST
TEST( AndOp, MatchesSingleClause ) {
BSONObj baseOperand = BSON( "$ne" << 5 );
auto_ptr<ComparisonMatchExpression> ne( new ComparisonMatchExpression() );
ASSERT( ne->init( "a", ComparisonMatchExpression::NE, baseOperand[ "$ne" ] ).isOK() );
AndMatchExpression andOp;
andOp.add( ne.release() );
ASSERT( andOp.matches( BSON( "a" << 4 ), NULL ) );
ASSERT( andOp.matches( BSON( "a" << BSON_ARRAY( 4 << 6 ) ), NULL ) );
ASSERT( !andOp.matches( BSON( "a" << 5 ), NULL ) );
ASSERT( !andOp.matches( BSON( "a" << BSON_ARRAY( 4 << 5 ) ), NULL ) );
}
示例4: if
//.........这里部分代码省略.........
nextBounds = R2Annulus(nextBounds.center(),
max(0.0, nextBounds.getInner() - epsilon),
nextBounds.getOuter());
}
if (nextBounds.getOuter() > 0 && nextBounds.getOuter() == _fullBounds.getOuter()) {
// We're at the max bound of the search, adjust interval maximum
nextBounds = R2Annulus(nextBounds.center(),
nextBounds.getInner(),
nextBounds.getOuter() + epsilon);
}
// *Always* adjust the covering bounds to be more inclusive
coverRegion.reset(new R2Annulus(nextBounds.center(),
max(0.0, nextBounds.getInner() - epsilon),
nextBounds.getOuter() + epsilon));
}
else {
invariant(SPHERE == queryCRS);
// TODO: As above, make this consistent with $within : $centerSphere
// Our intervals aren't in the same CRS as our index, so we need to adjust them
coverRegion.reset(new R2Annulus(projectBoundsToTwoDDegrees(nextBounds)));
}
//
// Setup the stages for this interval
//
IndexScanParams scanParams;
scanParams.descriptor = _twoDIndex;
scanParams.direction = 1;
// We use a filter on the key. The filter rejects keys that don't intersect with the
// annulus. An object that is in the annulus might have a key that's not in it and a key
// that's in it. As such we can't just look at one key per object.
//
// This does force us to do our own deduping of results, though.
scanParams.doNotDedup = true;
// Scan bounds on 2D indexes are only over the 2D field - other bounds aren't applicable.
// This is handled in query planning.
scanParams.bounds = _nearParams.baseBounds;
// The "2d" field is always the first in the index
const string twoDFieldName = _nearParams.nearQuery.field;
const int twoDFieldPosition = 0;
OrderedIntervalList coveredIntervals;
coveredIntervals.name = scanParams.bounds.fields[twoDFieldPosition].name;
ExpressionMapping::cover2d(*coverRegion,
_twoDIndex->infoObj(),
internalGeoNearQuery2DMaxCoveringCells,
&coveredIntervals);
// Intersect the $near bounds we just generated into the bounds we have for anything else
// in the scan (i.e. $within)
IndexBoundsBuilder::intersectize(coveredIntervals,
&scanParams.bounds.fields[twoDFieldPosition]);
// These parameters are stored by the index, and so must be ok
GeoHashConverter::Parameters hashParams;
GeoHashConverter::parseParameters(_twoDIndex->infoObj(), &hashParams);
MatchExpression* keyMatcher =
new TwoDKeyInRegionExpression(coverRegion.release(),
hashParams,
twoDFieldName);
// 2D indexes support covered search over additional fields they contain
// TODO: Don't need to clone, can just attach to custom matcher above
if (_nearParams.filter) {
AndMatchExpression* andMatcher = new AndMatchExpression();
andMatcher->add(keyMatcher);
andMatcher->add(_nearParams.filter->shallowClone());
keyMatcher = andMatcher;
}
// IndexScanWithMatch owns the matcher
IndexScan* scan = new IndexScanWithMatch(txn, scanParams, workingSet, keyMatcher);
MatchExpression* docMatcher = NULL;
// FLAT searches need to add an additional annulus $within matcher, see above
if (FLAT == queryCRS) {
docMatcher = new TwoDPtInAnnulusExpression(_fullBounds, twoDFieldName);
}
// FetchStage owns index scan
FetchStage* fetcher(new FetchStageWithMatch(workingSet,
scan,
docMatcher,
collection));
return StatusWith<CoveredInterval*>(new CoveredInterval(fetcher,
true,
nextBounds.getInner(),
nextBounds.getOuter(),
isLastInterval));
}