summaryrefslogtreecommitdiff
path: root/src/mongo/db/matcher/expression_text.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/matcher/expression_text.cpp')
-rw-r--r--src/mongo/db/matcher/expression_text.cpp62
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());
}