summaryrefslogtreecommitdiff
path: root/jstests/libs/fts.js
blob: eb5baec8a5a0c05be4c339f8f91c28d575ccb80a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// 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;
    });
}