mirror of
https://github.com/mongodb/mongo.git
synced 2024-11-24 00:17:37 +01:00
31 lines
820 B
JavaScript
31 lines
820 B
JavaScript
// Utility functions for FTS tests
|
|
//
|
|
export 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
|
|
export function getIDS(cursor) {
|
|
if (!cursor)
|
|
return [];
|
|
|
|
return cursor.map(function(z) {
|
|
return z._id;
|
|
});
|
|
}
|