0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00
mongodb/jstests/libs/fts.js
2014-12-30 11:52:20 -05:00

26 lines
794 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; } );
}