コード例 #1
0
ファイル: btreecursor.cpp プロジェクト: tanfulai/mongo
 // Check if the current key is beyond endKey.
 void BtreeCursor::checkEnd() {
     if ( bucket.isNull() )
         return;
     int cmp = sgn( endKey.woCompare( currKey(), order ) );
     if ( cmp != 0 && cmp != direction )
         bucket = DiskLoc();
 }
コード例 #2
0
ファイル: btreecursor.cpp プロジェクト: FrancescaK/mongo
 void BtreeCursor::noteLocation() {
     if ( !eof() ) {
         BSONObj o = currKey().getOwned();
         keyAtKeyOfs = o;
         locAtKeyOfs = currLoc();
     }
 }
コード例 #3
0
ファイル: btreecursor.cpp プロジェクト: FrancescaK/mongo
 bool BtreeCursor::skipOutOfRangeKeysAndCheckEnd() {
     if ( !ok() ) {
         return false;
     }
     int ret = _boundsIterator->advance( currKey() );
     if ( ret == -2 ) {
         bucket = DiskLoc();
         return false;
     }
     else if ( ret == -1 ) {
         ++_nscanned;
         return false;
     }
     ++_nscanned;
     advanceTo( currKey(), ret, _boundsIterator->after(), _boundsIterator->cmp(), _boundsIterator->inc() );
     return true;
 }
コード例 #4
0
void ImageTextEditor::updateText()
{
    storeText();
    newlang->setText(languages->currentText());
    newkey->setText(keys->currentText());
    QString t = image.text(currKey(),currLang());

    text->setText(t);
}
コード例 #5
0
ファイル: btreecursor.cpp プロジェクト: Bamco/mongo
 bool BtreeCursor::currentMatches( MatchDetails* details ) {
     // If currKey() might not match the specified _bounds, check whether or not it does.
     if ( !_boundsMustMatch && _bounds && !_bounds->matchesKey( currKey() ) ) {
         // If the key does not match _bounds, it does not match the query.
         return false;
     }
     // Forward to the base class implementation, which may utilize a Matcher.
     return Cursor::currentMatches( details );
 }
コード例 #6
0
ファイル: btreecursor.cpp プロジェクト: FrancescaK/mongo
 // Check if the current key is beyond endKey.
 void BtreeCursor::checkEnd() {
     if ( bucket.isNull() )
         return;
     if ( !endKey.isEmpty() ) {
         int cmp = sgn( endKey.woCompare( currKey(), _order ) );
         if ( ( cmp != 0 && cmp != _direction ) ||
                 ( cmp == 0 && !_endKeyInclusive ) )
             bucket = DiskLoc();
     }
 }
コード例 #7
0
ファイル: btreecursor.cpp プロジェクト: syntion/mongo
    // Check if the current key is beyond endKey.
    void BtreeCursor::checkEnd() {
        if (!ok()) { return; }

        if ( !endKey.isEmpty() ) {
            int cmp = sgn( endKey.woCompare( currKey(), _order ) );
            if ( ( cmp != 0 && cmp != _direction ) || ( cmp == 0 && !_endKeyInclusive ) ) {
                _hitEnd = true;
            }
        }
    }
コード例 #8
0
ファイル: clientcursor.cpp プロジェクト: ALFIO/mongo
    bool ClientCursor::getFieldsDotted( const string& name, BSONElementSet &ret ) {
        
        map<string,int>::const_iterator i = _indexedFields.find( name );
        if ( i == _indexedFields.end() ){
            current().getFieldsDotted( name , ret );
            return false;
        }

        int x = i->second;
        
        BSONObjIterator it( currKey() );
        while ( x && it.more() )
            it.next();
        assert( x == 0 );
        ret.insert( it.next() );
        return true;
    }
コード例 #9
0
    void IntervalBtreeCursor::relocateEnd() {
        if ( eof() ) {
            return;
        }

        // If the current key is above the upper bound ...
        int32_t cmp = currKey().woCompare( _upperBound, _ordering, false );
        if ( cmp > 0 || ( cmp == 0 && !_upperBoundInclusive ) ) {

            // ... then iteration is complete.
            _curr.bucket.Null();
            return;
        }

        // Otherwise, relocate _end.
        _end = locateKey( _upperBound, _upperBoundInclusive );
        skipUnused( &_end );
    }
コード例 #10
0
ファイル: clientcursor.cpp プロジェクト: chanwit/mongo
    BSONElement ClientCursor::getFieldDotted( const string& name , bool * fromKey ) {

        map<string,int>::const_iterator i = _indexedFields.find( name );
        if ( i == _indexedFields.end() ) {
            if ( fromKey )
                *fromKey = false;
            return current().getFieldDotted( name );
        }
        
        int x = i->second;

        BSONObjIterator it( currKey() );
        while ( x && it.more() ) {
            it.next();
            x--;
        }
        assert( x == 0 );

        if ( fromKey )
            *fromKey = true;
        return it.next();
    }
コード例 #11
0
ファイル: s2_near_cursor.cpp プロジェクト: p3we/mongo
// Fill _results with all of the results in the annulus defined by _innerRadius and
// _outerRadius.  If no results are found, grow the annulus and repeat until success (or
// until the edge of the world).
void S2NearIndexCursor::fillResults() {
    verify(_results.empty());
    if (_innerRadius >= _outerRadius) {
        return;
    }
    if (_innerRadius > _maxDistance) {
        return;
    }

    // We iterate until 1. our search radius is too big or 2. we find results.
    do {
        // Some of these arguments are opaque, look at the definitions of the involved classes.
        FieldRangeSet frs(_descriptor->parentNS().c_str(), makeFRSObject(), false, false);
        shared_ptr<FieldRangeVector> frv(new FieldRangeVector(frs, _specForFRV, 1));
        scoped_ptr<BtreeCursor> cursor(BtreeCursor::make(nsdetails(_descriptor->parentNS()),
                                       _descriptor->getOnDisk(), frv, 0, 1));

        // The cursor may return the same obj more than once for a given
        // FRS, so we make sure to only consider it once in any given annulus.
        //
        // We don't want this outside of the 'do' loop because the covering
        // for an annulus may return an object whose distance to the query
        // point is actually contained in a subsequent annulus.  If we
        // didn't consider every object in a given annulus we might miss
        // the point.
        //
        // We don't use a global 'seen' because we get that by requiring
        // the distance from the query point to the indexed geo to be
        // within our 'current' annulus, and I want to dodge all yield
        // issues if possible.
        unordered_set<DiskLoc, DiskLoc::Hasher> seen;

        LOG(1) << "looking at annulus from " << _innerRadius << " to " << _outerRadius << endl;
        LOG(1) << "Total # returned: " << _stats._numReturned << endl;
        // Do the actual search through this annulus.
        for (; cursor->ok(); cursor->advance()) {
            // Don't bother to look at anything we've returned.
            if (_returned.end() != _returned.find(cursor->currLoc())) {
                ++_stats._returnSkip;
                continue;
            }

            ++_stats._nscanned;
            if (seen.end() != seen.find(cursor->currLoc())) {
                ++_stats._btreeDups;
                continue;
            }

            // Get distance interval from our query point to the cell.
            // If it doesn't overlap with our current shell, toss.
            BSONObj currKey(cursor->currKey());
            BSONObjIterator it(currKey);
            BSONElement geoKey;
            for (int i = 0; i <= _nearFieldIndex; ++i) {
                geoKey = it.next();
            }

            S2Cell keyCell = S2Cell(S2CellId::FromString(geoKey.String()));
            if (!_annulus.MayIntersect(keyCell)) {
                ++_stats._keyGeoSkip;
                continue;
            }

            // We have to add this document to seen *AFTER* the key intersection test.
            // A geometry may have several keys, one of which may be in our search shell and one
            // of which may be outside of it.  We don't want to ignore a document just because
            // one of its covers isn't inside this annulus.
            seen.insert(cursor->currLoc());

            // At this point forward, we will not examine the document again in this annulus.

            const BSONObj& indexedObj = cursor->currLoc().obj();

            // Match against indexed geo fields.
            ++_stats._geoMatchTested;
            size_t geoFieldsMatched = 0;
            // See if the object actually overlaps w/the geo query fields.
            for (size_t i = 0; i < _indexedGeoFields.size(); ++i) {
                BSONElementSet geoFieldElements;
                indexedObj.getFieldsDotted(_indexedGeoFields[i].getField(), geoFieldElements,
                                           false);
                if (geoFieldElements.empty()) {
                    continue;
                }

                bool match = false;

                for (BSONElementSet::iterator oi = geoFieldElements.begin();
                        !match && (oi != geoFieldElements.end()); ++oi) {
                    if (!oi->isABSONObj()) {
                        continue;
                    }
                    const BSONObj &geoObj = oi->Obj();
                    GeometryContainer geoContainer;
                    uassert(16762, "ill-formed geometry: " + geoObj.toString(),
                            geoContainer.parseFrom(geoObj));
                    match = _indexedGeoFields[i].satisfiesPredicate(geoContainer);
                }

                if (match) {
                    ++geoFieldsMatched;
                }
            }

            if (geoFieldsMatched != _indexedGeoFields.size()) {
                continue;
            }

            // Get all the fields with that name from the document.
            BSONElementSet geoFieldElements;
            indexedObj.getFieldsDotted(_nearQuery.field, geoFieldElements, false);
            if (geoFieldElements.empty()) {
                continue;
            }

            ++_stats._inAnnulusTested;
            double minDistance = 1e20;
            // Look at each field in the document and take the min. distance.
            for (BSONElementSet::iterator oi = geoFieldElements.begin();
                    oi != geoFieldElements.end(); ++oi) {
                if (!oi->isABSONObj()) {
                    continue;
                }
                double dist = distanceTo(oi->Obj());
                minDistance = min(dist, minDistance);
            }

            // We could be in an annulus, yield, add new points closer to
            // query point than the last point we returned, then unyield.
            // This would return points out of order.
            if (minDistance < _returnedDistance) {
                continue;
            }

            // If the min. distance satisfies our distance criteria
            if (minDistance >= _innerRadius && minDistance < _outerRadius) {
                // The result is valid.  We have to de-dup ourselves here.
                if (_returned.end() == _returned.find(cursor->currLoc())) {
                    _results.push(Result(cursor->currLoc(), cursor->currKey(),
                                         minDistance));
                }
            }
        }

        if (_results.empty()) {
            LOG(1) << "results empty!\n";
            _radiusIncrement *= 2;
            nextAnnulus();
        } else if (_results.size() < 300) {
            _radiusIncrement *= 2;
        } else if (_results.size() > 600) {
            _radiusIncrement /= 2;
        }
    } while (_results.empty()
             && _innerRadius < _maxDistance
             && _innerRadius < _outerRadius);
    LOG(1) << "Filled shell with " << _results.size() << " results" << endl;
}
コード例 #12
0
void ImageTextEditor::storeText()
{
    if ( currKey().length() > 0 ) {
	image.setText(currKey(),currLang(),currText());
    }
}
コード例 #13
0
void ImageTextEditor::removeText()
{
    image.setText(currKey(),currLang(),QString::null);
}