diff options
author | Mathias Stearn <mathias@10gen.com> | 2013-12-13 13:39:01 -0500 |
---|---|---|
committer | Mathias Stearn <mathias@10gen.com> | 2013-12-18 19:09:17 -0500 |
commit | 170e563e4cfa069f2128379e7b997e6777e0ee99 (patch) | |
tree | d4cbc8451e1ee33b120004a867bfcb25bfdca62d /src/mongo/db/pipeline/document.cpp | |
parent | 3e707bcd22b7c0e8275d25bf8e8b28c3cec4cc67 (diff) | |
download | mongo-170e563e4cfa069f2128379e7b997e6777e0ee99.tar.gz |
SERVER-11675 Agg text support
To enable this, Documents now can store "metadata" that gets carried though
the pipeline as long as the result is the same logical document. This includes
crossing the shard-to-merger boundary.
Diffstat (limited to 'src/mongo/db/pipeline/document.cpp')
-rw-r--r-- | src/mongo/db/pipeline/document.cpp | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/mongo/db/pipeline/document.cpp b/src/mongo/db/pipeline/document.cpp index f7e41fc6606..4f260591fe1 100644 --- a/src/mongo/db/pipeline/document.cpp +++ b/src/mongo/db/pipeline/document.cpp @@ -195,6 +195,8 @@ namespace mongo { out->_usedBytes = _usedBytes; out->_numFields = _numFields; out->_hashTabMask = _hashTabMask; + out->_hasTextScore = _hasTextScore; + out->_textScore = _textScore; // Tell values that they have been memcpyed (updates ref counts) for (DocumentStorageIterator it = out->iteratorAll(); !it.atEnd(); it.advance()) { @@ -243,6 +245,35 @@ namespace mongo { return bb.obj(); } + const StringData Document::metaFieldTextScore("$textScore", StringData::LiteralTag()); + + BSONObj Document::toBsonWithMetaData() const { + BSONObjBuilder bb; + toBson(&bb); + if (hasTextScore()) + bb.append(metaFieldTextScore, getTextScore()); + return bb.obj(); + } + + Document Document::fromBsonWithMetaData(const BSONObj& bson) { + MutableDocument md; + + BSONObjIterator it(bson); + while(it.more()) { + BSONElement elem(it.next()); + if (elem.fieldName()[0] == '$') { + if (elem.fieldNameStringData() == metaFieldTextScore) { + md.setTextScore(elem.Double()); + continue; + } + } + + // Note: this will not parse out metadata in embedded documents. + md.addField(elem.fieldNameStringData(), Value(elem)); + } + + return md.freeze(); + } MutableDocument::MutableDocument(size_t expectedFields) : _storageHolder(NULL) @@ -393,6 +424,14 @@ namespace mongo { buf.appendStr(it->nameSD(), /*NUL byte*/ true); it->val.serializeForSorter(buf); } + + if (hasTextScore()) { + buf.appendNum(char(1)); + buf.appendNum(getTextScore()); + } + else { + buf.appendNum(char(0)); + } } Document Document::deserializeForSorter(BufReader& buf, const SorterDeserializeSettings&) { @@ -403,6 +442,10 @@ namespace mongo { doc.addField(name, Value::deserializeForSorter(buf, Value::SorterDeserializeSettings())); } + + if (buf.read<char>()) // hasTextScore + doc.setTextScore(buf.read<double>()); + return doc.freeze(); } } |