当前位置: 首页>>代码示例>>C++>>正文


C++ MatchDetails类代码示例

本文整理汇总了C++中MatchDetails的典型用法代码示例。如果您正苦于以下问题:C++ MatchDetails类的具体用法?C++ MatchDetails怎么用?C++ MatchDetails使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了MatchDetails类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: currentMatches

 bool QueryResponseBuilder::currentMatches() {
     MatchDetails details;
     if ( _cursor->currentMatches( &details ) ) {
         return true;
     }
     _explain->noteIterate( false, false, details.hasLoadedRecord(), false );
     return false;
 }
开发者ID:JakubOboza,项目名称:mongo,代码行数:8,代码来源:query.cpp

示例2: run

 void run() {
     Matcher matcher( BSON( "a.b" << 1 ) );
     MatchDetails details;
     details.requestElemMatchKey();
     ASSERT( !details.hasElemMatchKey() );
     ASSERT( matcher.matches( fromjson( "{ a:[ { b:1 } ] }" ), &details ) );
     // The '0' entry of the 'a' array is matched.
     ASSERT( details.hasElemMatchKey() );
     ASSERT_EQUALS( string( "0" ), details.elemMatchKey() );
 }
开发者ID:Desartstudio,项目名称:mongo-nonx86,代码行数:10,代码来源:matchertests.cpp

示例3: run

 void run() {
     CollatorInterface* collator = nullptr;
     M matcher(BSON("a.b" << 1), ExtensionsCallbackDisallowExtensions(), collator);
     MatchDetails details;
     details.requestElemMatchKey();
     ASSERT(!details.hasElemMatchKey());
     ASSERT(matcher.matches(fromjson("{ a:[ { b:1 } ] }"), &details));
     // The '0' entry of the 'a' array is matched.
     ASSERT(details.hasElemMatchKey());
     ASSERT_EQUALS(string("0"), details.elemMatchKey());
 }
开发者ID:GodotGo,项目名称:mongo,代码行数:11,代码来源:matchertests.cpp

示例4: run

 void run() {
     boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
     M matcher(BSON("a.b" << 1), expCtx);
     MatchDetails details;
     details.requestElemMatchKey();
     ASSERT(!details.hasElemMatchKey());
     ASSERT(matcher.matches(fromjson("{ a:[ { b:1 } ] }"), &details));
     // The '0' entry of the 'a' array is matched.
     ASSERT(details.hasElemMatchKey());
     ASSERT_EQUALS(string("0"), details.elemMatchKey());
 }
开发者ID:ShaneHarvey,项目名称:mongo,代码行数:11,代码来源:matchertests.cpp

示例5: TEST

TEST( ElemMatchValueMatchExpression, ElemMatchKey ) {
    BSONObj baseOperand = BSON( "$gt" << 6 );
    auto_ptr<ComparisonMatchExpression> gt( new ComparisonMatchExpression() );
    ASSERT( gt->init( "", ComparisonMatchExpression::GT, baseOperand[ "$gt" ] ).isOK() );
    ElemMatchValueMatchExpression op;
    ASSERT( op.init( "a.b", gt.release() ).isOK() );
    MatchDetails details;
    details.requestElemMatchKey();
    ASSERT( !op.matches( BSONObj(), &details ) );
    ASSERT( !details.hasElemMatchKey() );
    ASSERT( !op.matches( BSON( "a" << BSON( "b" << BSON_ARRAY( 2 ) ) ),
                         &details ) );
    ASSERT( !details.hasElemMatchKey() );
    ASSERT( op.matches( BSON( "a" << BSON( "b" << BSON_ARRAY( 3 << 7 ) ) ),
                        &details ) );
    ASSERT( details.hasElemMatchKey() );
    // The entry within the $elemMatch array is reported.
    ASSERT_EQUALS( "1", details.elemMatchKey() );
    ASSERT( op.matches( BSON( "a" <<
                              BSON_ARRAY( 1 << 2 <<
                                          BSON( "b" << BSON_ARRAY( 3 << 7 ) ) ) ),
                        &details ) );
    ASSERT( details.hasElemMatchKey() );
    // The entry within a parent of the $elemMatch array is reported.
    ASSERT_EQUALS( "2", details.elemMatchKey() );
}
开发者ID:harish80,项目名称:mongo,代码行数:26,代码来源:expression_array_test.cpp

示例6: TEST

TEST(NotMatchExpression, ElemMatchKey) {
    BSONObj baseOperand = BSON("$lt" << 5);
    unique_ptr<ComparisonMatchExpression> lt(new LTMatchExpression());
    ASSERT(lt->init("a", baseOperand["$lt"]).isOK());
    NotMatchExpression notOp;
    ASSERT(notOp.init(lt.release()).isOK());
    MatchDetails details;
    details.requestElemMatchKey();
    ASSERT(!notOp.matchesBSON(BSON("a" << BSON_ARRAY(1)), &details));
    ASSERT(!details.hasElemMatchKey());
    ASSERT(notOp.matchesBSON(BSON("a" << 6), &details));
    ASSERT(!details.hasElemMatchKey());
    ASSERT(notOp.matchesBSON(BSON("a" << BSON_ARRAY(6)), &details));
    // elemMatchKey is not implemented for negative match operators.
    ASSERT(!details.hasElemMatchKey());
}
开发者ID:AshishSanju,项目名称:mongo,代码行数:16,代码来源:expression_tree_test.cpp

示例7: transform

Status ProjectionExec::transform(const BSONObj& in, BSONObj* out) const {
    // If it's a positional projection we need a MatchDetails.
    MatchDetails matchDetails;
    if (transformRequiresDetails()) {
        matchDetails.requestElemMatchKey();
        verify(NULL != _queryExpression);
        verify(_queryExpression->matchesBSON(in, &matchDetails));
    }

    BSONObjBuilder bob;
    Status s = transform(in, &bob, &matchDetails);
    if (!s.isOK()) {
        return s;
    }
    *out = bob.obj();
    return Status::OK();
}
开发者ID:AndrwFn,项目名称:mongo,代码行数:17,代码来源:projection_exec.cpp

示例8: getArrayOpType

    void Projection::transform( const BSONObj& in , BSONObjBuilder& b, const MatchDetails* details ) const {
        const ArrayOpType& arrayOpType = getArrayOpType();

        BSONObjIterator i(in);
        while ( i.more() ) {
            BSONElement e = i.next();
            if ( mongoutils::str::equals( "_id" , e.fieldName() ) ) {
                if ( _includeID )
                    b.append( e );
            }
            else {
                Matchers::const_iterator matcher = _matchers.find( e.fieldName() );
                if ( matcher == _matchers.end() ) {
                    // no array projection matchers for this field
                    append( b, e, details, arrayOpType );
                } else {
                    // field has array projection with $elemMatch specified.
                    massert( 16348, "matchers are only supported for $elemMatch", 
                             arrayOpType == ARRAY_OP_ELEM_MATCH );
                    MatchDetails arrayDetails;
                    arrayDetails.requestElemMatchKey();
                    if ( matcher->second->matches( in, &arrayDetails ) ) {
                        LOG(4) << "Matched array on field: " << matcher->first  << endl
                               << " from array: " << in.getField( matcher->first ) << endl
                               << " in object: " << in << endl
                               << " at position: " << arrayDetails.elemMatchKey() << endl;
                        FieldMap::const_iterator field = _fields.find( e.fieldName()  );
                        massert( 16349, "$elemMatch specified, but projection field not found.",
                            field != _fields.end() );
                        BSONArrayBuilder a;
                        BSONObjBuilder o;
                        massert( 16350, "$elemMatch called on document element with eoo",
                                 ! in.getField( e.fieldName() ).eoo() );
                        massert( 16351, "$elemMatch called on array element with eoo",
                                 ! in.getField( e.fieldName() ).Obj().getField(
                                        arrayDetails.elemMatchKey() ).eoo() );
                        a.append( in.getField( e.fieldName() ).Obj()
                                    .getField( arrayDetails.elemMatchKey() ) );
                        o.appendArray( matcher->first, a.arr() );
                        append( b, o.done().firstElement(), details, arrayOpType );
                    }
                }
            }
        }
    }
开发者ID:7segments,项目名称:mongo,代码行数:45,代码来源:projection.cpp

示例9: run

            void run() {
                client().insert( ns(), fromjson( "{ a:[ {}, { b:1 } ] }" ) );
                
                Client::Transaction transaction(DB_SERIALIZABLE);
                Client::ReadContext context( ns(), mongo::unittest::EMPTY_STRING );

                CoveredIndexMatcher matcher( BSON( "a.b" << 1 ), BSON( "$natural" << 1 ) );
                MatchDetails details;
                details.requestElemMatchKey();
                boost::shared_ptr<Cursor> cursor = getOptimizedCursor( ns(), BSONObj() );
                // Verify that the cursor is unindexed.
                ASSERT_EQUALS( "BasicCursor", cursor->toString() );
                ASSERT( matcher.matchesCurrent( cursor.get(), &details ) );
                // The '1' entry of the 'a' array is matched.
                ASSERT( details.hasElemMatchKey() );
                ASSERT_EQUALS( string( "1" ), details.elemMatchKey() );
                transaction.commit();
            }
开发者ID:7segments,项目名称:mongo,代码行数:18,代码来源:matchertests.cpp

示例10: i

        /*
         * Takes a cursor and updates the partial score for said cursor in _scores map
         * @param cursor, btree cursor pointing to the current document to be scored
         */
        void FTSSearch::_process( BtreeCursor* cursor ) {
            _keysLookedAt++;

            BSONObj key = cursor->currKey();

            BSONObjIterator i( key );
            for ( unsigned j = 0; j < _ftsSpec.numExtraBefore(); j++)
                i.next();
            i.next(); // move past indexToken
            BSONElement scoreElement = i.next();

            double score = scoreElement.number();

            double& cur = _scores[(cursor->currLoc()).rec()];

            if ( cur < 0 ) {
                // already been rejected
                return;
            }

            if ( cur == 0 && _matcher.get() ) {
                // we haven't seen this before and we have a matcher
                MatchDetails d;
                if ( !_matcher->matchesCurrent( cursor, &d ) ) {
                    cur = -1;
                }

                if ( d.hasLoadedRecord() )
                    _objectsLookedAt++;

                if ( cur == -1 )
                    return;
            }

            if ( cur )
                cur += score * (1 + 1 / score);
            else
                cur += score;

        }
开发者ID:10genReviews,项目名称:mongo,代码行数:44,代码来源:fts_search.cpp

示例11: TEST

TEST(OrOp, ElemMatchKey) {
    BSONObj baseOperand1 = BSON("a" << 1);
    BSONObj baseOperand2 = BSON("b" << 2);
    const CollatorInterface* collator = nullptr;
    unique_ptr<ComparisonMatchExpression> sub1(new EqualityMatchExpression(collator));
    ASSERT(sub1->init("a", baseOperand1["a"]).isOK());
    unique_ptr<ComparisonMatchExpression> sub2(new EqualityMatchExpression(collator));
    ASSERT(sub2->init("b", baseOperand2["b"]).isOK());

    OrMatchExpression orOp;
    orOp.add(sub1.release());
    orOp.add(sub2.release());

    MatchDetails details;
    details.requestElemMatchKey();
    ASSERT(!orOp.matchesBSON(BSONObj(), &details));
    ASSERT(!details.hasElemMatchKey());
    ASSERT(!orOp.matchesBSON(BSON("a" << BSON_ARRAY(10) << "b" << BSON_ARRAY(10)), &details));
    ASSERT(!details.hasElemMatchKey());
    ASSERT(orOp.matchesBSON(BSON("a" << BSON_ARRAY(1) << "b" << BSON_ARRAY(1 << 2)), &details));
    // The elem match key feature is not implemented for $or.
    ASSERT(!details.hasElemMatchKey());
}
开发者ID:AlexOreshkevich,项目名称:mongo,代码行数:23,代码来源:expression_tree_test.cpp

示例12: TEST

    TEST( OrOp, ElemMatchKey ) {
        BSONObj baseOperand1 = BSON( "a" << 1 );
        BSONObj baseOperand2 = BSON( "b" << 2 );
        auto_ptr<ComparisonMatchExpression> sub1( new ComparisonMatchExpression() );
        ASSERT( sub1->init( "a", ComparisonMatchExpression::EQ, baseOperand1[ "a" ] ).isOK() );
        auto_ptr<ComparisonMatchExpression> sub2( new ComparisonMatchExpression() );
        ASSERT( sub2->init( "b", ComparisonMatchExpression::EQ, baseOperand2[ "b" ] ).isOK() );

        OrMatchExpression orOp;
        orOp.add( sub1.release() );
        orOp.add( sub2.release() );

        MatchDetails details;
        details.requestElemMatchKey();
        ASSERT( !orOp.matches( BSONObj(), &details ) );
        ASSERT( !details.hasElemMatchKey() );
        ASSERT( !orOp.matches( BSON( "a" << BSON_ARRAY( 10 ) << "b" << BSON_ARRAY( 10 ) ),
                               &details ) );
        ASSERT( !details.hasElemMatchKey() );
        ASSERT( orOp.matches( BSON( "a" << BSON_ARRAY( 1 ) << "b" << BSON_ARRAY( 1 << 2 ) ),
                              &details ) );
        // The elem match key feature is not implemented for $or.
        ASSERT( !details.hasElemMatchKey() );
    }
开发者ID:gengyit,项目名称:mongo,代码行数:24,代码来源:expression_tree_test.cpp

示例13: transformAndUpdate

    void UpdateStage::transformAndUpdate(BSONObj& oldObj, DiskLoc& loc) {
        const UpdateRequest* request = _params.request;
        UpdateDriver* driver = _params.driver;
        CanonicalQuery* cq = _params.canonicalQuery;
        UpdateLifecycle* lifecycle = request->getLifecycle();

        // Ask the driver to apply the mods. It may be that the driver can apply those "in
        // place", that is, some values of the old document just get adjusted without any
        // change to the binary layout on the bson layer. It may be that a whole new
        // document is needed to accomodate the new bson layout of the resulting document.
        _doc.reset(oldObj, mutablebson::Document::kInPlaceEnabled);
        BSONObj logObj;

        FieldRefSet updatedFields;

        Status status = Status::OK();
        if (!driver->needMatchDetails()) {
            // If we don't need match details, avoid doing the rematch
            status = driver->update(StringData(), &_doc, &logObj, &updatedFields);
        }
        else {
            // If there was a matched field, obtain it.
            MatchDetails matchDetails;
            matchDetails.requestElemMatchKey();

            dassert(cq);
            verify(cq->root()->matchesBSON(oldObj, &matchDetails));

            string matchedField;
            if (matchDetails.hasElemMatchKey())
                matchedField = matchDetails.elemMatchKey();

            // TODO: Right now, each mod checks in 'prepare' that if it needs positional
            // data, that a non-empty StringData() was provided. In principle, we could do
            // that check here in an else clause to the above conditional and remove the
            // checks from the mods.

            status = driver->update(matchedField, &_doc, &logObj, &updatedFields);
        }

        if (!status.isOK()) {
            uasserted(16837, status.reason());
        }

        // Ensure _id exists and is first
        uassertStatusOK(ensureIdAndFirst(_doc));

        // If the driver applied the mods in place, we can ask the mutable for what
        // changed. We call those changes "damages". :) We use the damages to inform the
        // journal what was changed, and then apply them to the original document
        // ourselves. If, however, the driver applied the mods out of place, we ask it to
        // generate a new, modified document for us. In that case, the file manager will
        // take care of the journaling details for us.
        //
        // This code flow is admittedly odd. But, right now, journaling is baked in the file
        // manager. And if we aren't using the file manager, we have to do jounaling
        // ourselves.
        bool docWasModified = false;
        BSONObj newObj;
        const char* source = NULL;
        bool inPlace = _doc.getInPlaceUpdates(&_damages, &source);

        // If something changed in the document, verify that no immutable fields were changed
        // and data is valid for storage.
        if ((!inPlace || !_damages.empty()) ) {
            if (!(request->isFromReplication() || request->isFromMigration())) {
                const std::vector<FieldRef*>* immutableFields = NULL;
                if (lifecycle)
                    immutableFields = lifecycle->getImmutableFields();

                uassertStatusOK(validate(oldObj,
                                         updatedFields,
                                         _doc,
                                         immutableFields,
                                         driver->modOptions()) );
            }
        }


        // Save state before making changes
        saveState();

        {
            WriteUnitOfWork wunit(request->getOpCtx());

            if (inPlace && !driver->modsAffectIndices()) {
                // If a set of modifiers were all no-ops, we are still 'in place', but there
                // is no work to do, in which case we want to consider the object unchanged.
                if (!_damages.empty() ) {
                    // Don't actually do the write if this is an explain.
                    if (!request->isExplain()) {
                        invariant(_collection);
                        const RecordData oldRec(oldObj.objdata(), oldObj.objsize());
                        _collection->updateDocumentWithDamages(request->getOpCtx(), loc,
                                                               oldRec, source, _damages);
                    }
                    docWasModified = true;
                    _specificStats.fastmod = true;
                }

//.........这里部分代码省略.........
开发者ID:liuhg,项目名称:mongo,代码行数:101,代码来源:update.cpp

示例14: update


//.........这里部分代码省略.........
                else {
                    uassertStatusOK(Status(ErrorCodes::InternalError,
                                           str::stream() << " Update query failed -- "
                                                         << Runner::statestr(state)));
                }
            }

            // We fill this with the new locs of moved doc so we don't double-update.
            if (updatedLocs && updatedLocs->count(loc) > 0) {
                continue;
            }

            // We count how many documents we scanned even though we may skip those that are
            // deemed duplicated. The final 'numMatched' and 'nscanned' numbers may differ for
            // that reason.
            // TODO: Do we want to pull this out of the underlying query plan?
            opDebug->nscanned++;

            // Found a matching document
            opDebug->nscannedObjects++;
            numMatched++;

            // Ask the driver to apply the mods. It may be that the driver can apply those "in
            // place", that is, some values of the old document just get adjusted without any
            // change to the binary layout on the bson layer. It may be that a whole new
            // document is needed to accomodate the new bson layout of the resulting document.
            doc.reset(oldObj, mutablebson::Document::kInPlaceEnabled);
            BSONObj logObj;


            FieldRefSet updatedFields;

            Status status = Status::OK();
            if (!driver->needMatchDetails()) {
                // If we don't need match details, avoid doing the rematch
                status = driver->update(StringData(), &doc, &logObj, &updatedFields);
            }
            else {
                // If there was a matched field, obtain it.
                MatchDetails matchDetails;
                matchDetails.requestElemMatchKey();

                dassert(cq);
                verify(cq->root()->matchesBSON(oldObj, &matchDetails));

                string matchedField;
                if (matchDetails.hasElemMatchKey())
                    matchedField = matchDetails.elemMatchKey();

                // TODO: Right now, each mod checks in 'prepare' that if it needs positional
                // data, that a non-empty StringData() was provided. In principle, we could do
                // that check here in an else clause to the above conditional and remove the
                // checks from the mods.

                status = driver->update(matchedField, &doc, &logObj, &updatedFields);
            }

            if (!status.isOK()) {
                uasserted(16837, status.reason());
            }

            // Ensure _id exists and is first
            uassertStatusOK(ensureIdAndFirst(doc));

            // If the driver applied the mods in place, we can ask the mutable for what
            // changed. We call those changes "damages". :) We use the damages to inform the
开发者ID:PedroLai,项目名称:mongo,代码行数:67,代码来源:update.cpp

示例15: run

        bool run(const string& dbname, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl ) {
            Timer t;
            string ns = dbname + '.' + cmdObj.firstElement().valuestr();

            string key = cmdObj["key"].valuestrsafe();
            BSONObj keyPattern = BSON( key << 1 );

            BSONObj query = getQuery( cmdObj );

            int bufSize = BSONObjMaxUserSize - 4096;
            BufBuilder bb( bufSize );
            char * start = bb.buf();

            BSONArrayBuilder arr( bb );
            BSONElementSet values;

            long long nscanned = 0; // locations looked at
            long long nscannedObjects = 0; // full objects looked at
            long long n = 0; // matches
            MatchDetails md;

            Collection *cl = getCollection( ns );

            if ( ! cl ) {
                result.appendArray( "values" , BSONObj() );
                result.append( "stats" , BSON( "n" << 0 << "nscanned" << 0 << "nscannedObjects" << 0 ) );
                return true;
            }

            shared_ptr<Cursor> cursor;
            if ( ! query.isEmpty() ) {
                cursor = getOptimizedCursor(ns.c_str() , query , BSONObj() );
            }
            else {

                // query is empty, so lets see if we can find an index
                // with the key so we don't have to hit the raw data
                for (int i = 0; i < cl->nIndexes(); i++) {
                    IndexDetails &idx = cl->idx(i);
                    if (cl->isMultikey(i)) {
                        continue;
                    }

                    if ( idx.inKeyPattern( key ) ) {
                        cursor = getBestGuessCursor( ns.c_str() ,
                                                     BSONObj() ,
                                                     idx.keyPattern() );
                        if( cursor.get() ) break;
                    }

                }

                if ( ! cursor.get() ) {
                    cursor = getOptimizedCursor(ns.c_str() , query , BSONObj() );
                }

            }

            
            verify( cursor );
            string cursorName = cursor->toString();
            
            auto_ptr<ClientCursor> cc (new ClientCursor(QueryOption_NoCursorTimeout, cursor, ns));

            for ( ; cursor->ok(); cursor->advance() ) {
                nscanned++;
                bool loadedRecord = false;

                if ( cursor->currentMatches( &md ) && !cursor->getsetdup( cursor->currPK() ) ) {
                    n++;

                    BSONObj holder;
                    BSONElementSet temp;
                    loadedRecord = ! cc->getFieldsDotted( key , temp, holder );

                    for ( BSONElementSet::iterator i=temp.begin(); i!=temp.end(); ++i ) {
                        BSONElement e = *i;
                        if ( values.count( e ) )
                            continue;

                        int now = bb.len();

                        uassert(10044,  "distinct too big, 16mb cap", ( now + e.size() + 1024 ) < bufSize );

                        arr.append( e );
                        BSONElement x( start + now );

                        values.insert( x );
                    }
                }

                if ( loadedRecord || md.hasLoadedRecord() )
                    nscannedObjects++;

                RARELY killCurrentOp.checkForInterrupt();
            }

            verify( start == bb.buf() );

            result.appendArray( "values" , arr.done() );
//.........这里部分代码省略.........
开发者ID:7segments,项目名称:mongo,代码行数:101,代码来源:distinct.cpp


注:本文中的MatchDetails类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。