0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 01:21:03 +01:00
mongodb/jstests/libs/fts.js
2016-05-28 17:55:12 -04:00

31 lines
806 B
JavaScript

// Utility functions for FTS tests
//
function queryIDS(coll, search, filter, extra, limit) {
var query = {"$text": {"$search": search}};
if (extra)
query = {"$text": Object.extend({"$search": search}, extra)};
if (filter)
Object.extend(query, filter);
var result;
if (limit)
result = coll.find(query, {score: {"$meta": "textScore"}})
.sort({score: {"$meta": "textScore"}})
.limit(limit);
else
result =
coll.find(query, {score: {"$meta": "textScore"}}).sort({score: {"$meta": "textScore"}});
return getIDS(result);
}
// Return an array of _ids from a cursor
function getIDS(cursor) {
if (!cursor)
return [];
return cursor.map(function(z) {
return z._id;
});
}