summaryrefslogtreecommitdiff
path: root/src/mongo/db
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db')
-rw-r--r--src/mongo/db/matcher/expression_serialization_test.cpp16
-rw-r--r--src/mongo/db/matcher/expression_tree.cpp11
2 files changed, 26 insertions, 1 deletions
diff --git a/src/mongo/db/matcher/expression_serialization_test.cpp b/src/mongo/db/matcher/expression_serialization_test.cpp
index 63f238593ae..74a8d3b8f74 100644
--- a/src/mongo/db/matcher/expression_serialization_test.cpp
+++ b/src/mongo/db/matcher/expression_serialization_test.cpp
@@ -1377,6 +1377,22 @@ TEST(SerializeBasic, ExpressionTextSerializesCorrectly) {
ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), serialize(reserialized.getMatchExpression()));
}
+TEST(SerializeBasic, ExpressionNorWithTextSerializesCorrectly) {
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ Matcher original(fromjson("{$nor: [{$text: {$search: 'x'}}]}"),
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
+ Matcher reserialized(serialize(original.getMatchExpression()),
+ expCtx,
+ ExtensionsCallbackNoop(),
+ MatchExpressionParser::kAllowAllSpecialFeatures);
+ ASSERT_BSONOBJ_EQ(*reserialized.getQuery(),
+ fromjson("{$nor: [{$text: {$search: 'x', $language: '', $caseSensitive: "
+ "false, $diacriticSensitive: false}}]}"));
+ ASSERT_BSONOBJ_EQ(*reserialized.getQuery(), serialize(reserialized.getMatchExpression()));
+}
+
TEST(SerializeBasic, ExpressionTextWithDefaultLanguageSerializesCorrectly) {
boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
Matcher original(fromjson("{$text: {$search: 'a', $caseSensitive: false}}"),
diff --git a/src/mongo/db/matcher/expression_tree.cpp b/src/mongo/db/matcher/expression_tree.cpp
index c24749ea7b3..2229f602895 100644
--- a/src/mongo/db/matcher/expression_tree.cpp
+++ b/src/mongo/db/matcher/expression_tree.cpp
@@ -37,6 +37,7 @@
#include "mongo/bson/bsonobjbuilder.h"
#include "mongo/db/matcher/expression_always_boolean.h"
#include "mongo/db/matcher/expression_path.h"
+#include "mongo/db/matcher/expression_text_base.h"
namespace mongo {
@@ -324,6 +325,14 @@ void NotMatchExpression::debugString(StringBuilder& debug, int level) const {
boost::optional<StringData> NotMatchExpression::getPathIfNotWithSinglePathMatchExpressionTree(
MatchExpression* exp) {
if (auto pathMatch = dynamic_cast<PathMatchExpression*>(exp)) {
+ if (dynamic_cast<TextMatchExpressionBase*>(exp)) {
+ // While TextMatchExpressionBase derives from PathMatchExpression, text match
+ // expressions cannot be serialized in the same manner as other PathMatchExpression
+ // derivatives. This is because the path for a TextMatchExpression is embedded within
+ // the $text object, whereas for other PathMatchExpressions it is on the left-hand-side,
+ // for example {x: {$eq: 1}}.
+ return boost::none;
+ }
return pathMatch->path();
}
@@ -331,7 +340,7 @@ boost::optional<StringData> NotMatchExpression::getPathIfNotWithSinglePathMatchE
boost::optional<StringData> path;
for (size_t i = 0; i < exp->numChildren(); ++i) {
auto pathMatchChild = dynamic_cast<PathMatchExpression*>(exp->getChild(i));
- if (!pathMatchChild) {
+ if (!pathMatchChild || dynamic_cast<TextMatchExpressionBase*>(exp->getChild(i))) {
return boost::none;
}