diff options
author | Blake Oler <blake.oler@10gen.com> | 2017-09-11 16:05:43 -0400 |
---|---|---|
committer | Kyle Suarez <kyle.suarez@mongodb.com> | 2017-11-14 13:52:23 -0500 |
commit | acde99b058c6e23302bc849015ed5e90b15b19fc (patch) | |
tree | cc1775bd2272048d55c936b3f4c259931f8409d6 /src/mongo/db/matcher/expression_text.cpp | |
parent | 4abdc7aff5cd5d0531c53b0ff784826e96700418 (diff) | |
download | mongo-acde99b058c6e23302bc849015ed5e90b15b19fc.tar.gz |
SERVER-30783 Move init() logic to MatchExpression constructors
Diffstat (limited to 'src/mongo/db/matcher/expression_text.cpp')
-rw-r--r-- | src/mongo/db/matcher/expression_text.cpp | 62 |
1 files changed, 32 insertions, 30 deletions
diff --git a/src/mongo/db/matcher/expression_text.cpp b/src/mongo/db/matcher/expression_text.cpp index 1719cda7a21..33c388bd607 100644 --- a/src/mongo/db/matcher/expression_text.cpp +++ b/src/mongo/db/matcher/expression_text.cpp @@ -42,9 +42,13 @@ namespace mongo { -Status TextMatchExpression::init(OperationContext* opCtx, - const NamespaceString& nss, - TextParams params) { +TextMatchExpression::TextMatchExpression(fts::FTSQueryImpl ftsQuery) + : TextMatchExpressionBase("_fts"), _ftsQuery(ftsQuery) {} + +TextMatchExpression::TextMatchExpression(OperationContext* opCtx, + const NamespaceString& nss, + TextParams params) + : TextMatchExpressionBase("_fts") { _ftsQuery.setQuery(std::move(params.query)); _ftsQuery.setLanguage(std::move(params.language)); _ftsQuery.setCaseSensitive(params.caseSensitive); @@ -56,28 +60,31 @@ Status TextMatchExpression::init(OperationContext* opCtx, AutoGetDb autoDb(opCtx, nss.db(), MODE_IS); Lock::CollectionLock collLock(opCtx->lockState(), nss.ns(), MODE_IS); Database* db = autoDb.getDb(); - if (!db) { - return {ErrorCodes::IndexNotFound, - str::stream() << "text index required for $text query (no such collection '" - << nss.ns() - << "')"}; - } + + uassert(ErrorCodes::IndexNotFound, + str::stream() << "text index required for $text query (no such collection '" + << nss.ns() + << "')", + db); + Collection* collection = db->getCollection(opCtx, nss); - if (!collection) { - return {ErrorCodes::IndexNotFound, - str::stream() << "text index required for $text query (no such collection '" - << nss.ns() - << "')"}; - } + + uassert(ErrorCodes::IndexNotFound, + str::stream() << "text index required for $text query (no such collection '" + << nss.ns() + << "')", + collection); + std::vector<IndexDescriptor*> idxMatches; collection->getIndexCatalog()->findIndexByType(opCtx, IndexNames::TEXT, idxMatches); - if (idxMatches.empty()) { - return {ErrorCodes::IndexNotFound, "text index required for $text query"}; - } - if (idxMatches.size() > 1) { - return {ErrorCodes::IndexNotFound, "more than one text index found for $text query"}; - } + + uassert( + ErrorCodes::IndexNotFound, "text index required for $text query", !idxMatches.empty()); + uassert(ErrorCodes::IndexNotFound, + "more than one text index found for $text query", + idxMatches.size() < 2); invariant(idxMatches.size() == 1); + IndexDescriptor* index = idxMatches[0]; const FTSAccessMethod* fam = static_cast<FTSAccessMethod*>(collection->getIndexCatalog()->getIndex(index)); @@ -91,19 +98,14 @@ Status TextMatchExpression::init(OperationContext* opCtx, } Status parseStatus = _ftsQuery.parse(version); - if (!parseStatus.isOK()) { - return parseStatus; - } - - return setPath("_fts"); + uassertStatusOK(parseStatus); } std::unique_ptr<MatchExpression> TextMatchExpression::shallowClone() const { - auto expr = stdx::make_unique<TextMatchExpression>(); - // We initialize _ftsQuery here directly rather than calling init(), to avoid needing to examine + auto expr = stdx::make_unique<TextMatchExpression>(_ftsQuery); + // We use the query-only constructor here directly rather than using the full constructor, to + // avoid needing to examine // the index catalog. - expr->_ftsQuery = _ftsQuery; - invariantOK(expr->setPath("_fts")); if (getTag()) { expr->setTag(getTag()->clone()); } |