summaryrefslogtreecommitdiff
path: root/jstests
diff options
context:
space:
mode:
authorTed Tuckman <ted.tuckman@mongodb.com>2020-01-27 14:06:08 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-03-05 18:37:45 +0000
commit210c31bd821cea37506b00f803911c91f337cab2 (patch)
treebbd6c767e3b6f1a6541fd0139762c25ff6efa144 /jstests
parentebee38a03f01f8a9969004f686cb0663d05447ed (diff)
downloadmongo-210c31bd821cea37506b00f803911c91f337cab2.tar.gz
SERVER-45363 Base weight for text index on exact match not possible match
(cherry picked from commit 4bb2ad4c48c07d267c98f5443e0984a5e1ef7209)
Diffstat (limited to 'jstests')
-rw-r--r--jstests/core/fts_index_wildcard_and_weight.js44
1 files changed, 44 insertions, 0 deletions
diff --git a/jstests/core/fts_index_wildcard_and_weight.js b/jstests/core/fts_index_wildcard_and_weight.js
new file mode 100644
index 00000000000..9397be5cb9a
--- /dev/null
+++ b/jstests/core/fts_index_wildcard_and_weight.js
@@ -0,0 +1,44 @@
+// Test that on a text index that matches all fields does not use a weight from a named field.
+// This test was designed to reproduce SERVER-45363.
+// @tags: [requires_fcv_44]
+//
+(function() {
+"use strict";
+var coll = db.getCollection(jsTestName());
+coll.drop();
+
+assert.commandWorked(coll.createIndex(
+ {"$**": "text"}, {name: "fullTextIndex", weights: {name: 500}, default_language: "english"}));
+assert.commandWorked(coll.insert({name: 'Spot', guardian: 'Kevin'}));
+assert.commandWorked(coll.insert({name: 'Kevin', guardian: 'Spot'}));
+var results = coll.aggregate([
+ {$match: {$text: {$search: "Kevin"}}},
+ {$sort: {score: {$meta: "textScore"}}},
+ {$project: {name: 1, score: {$meta: "textScore"}}}
+ ])
+ .toArray();
+assert.gt(results[0].score, results[1].score);
+assert.eq(results[0].name, "Kevin");
+
+coll.drop();
+assert.commandWorked(coll.createIndex(
+ {"$**": "text"},
+ {name: "fullTextIndex", weights: {name: 500, tag: 250}, default_language: "english"}));
+assert.commandWorked(coll.insert({name: 'Spot', guardian: 'Kevin', special: 'Dog', tag: 'Nice'}));
+assert.commandWorked(coll.insert({name: 'Kevin', guardian: 'Spot', special: 'Human', tag: 'Mean'}));
+assert.commandWorked(
+ coll.insert({name: 'Whiskers', guardian: 'Carl', special: 'Cat', tag: 'Kevin'}));
+assert.commandWorked(
+ coll.insert({name: 'McFlufferson', guardian: 'Steve', special: 'Kevin', tag: 'Fluffy'}));
+
+results = coll.aggregate([
+ {$match: {$text: {$search: "Kevin"}}},
+ {$sort: {score: {$meta: "textScore"}}},
+ {$project: {name: 1, score: {$meta: "textScore"}}}
+ ])
+ .toArray();
+assert.eq(results[0].name, "Kevin", results);
+assert.eq(results[1].name, "Whiskers", results);
+assert.gt(results[0].score, results[1].score, results);
+assert.eq(results[2].score, results[3].score, results);
+})();