I am working on a search function. I have an object containing data in a pair of key values, where the key is the identifier of the object, and the value is the score that I calculated using some background process. Thus, my case while searching for fora data, I have to add an account, counted before that with a new account.
I use aggregation for my search operation. The following is a snippet of code.
Document
{ "_id": ObjectId("57de00eb0b1e50fa66290198"), "id": "205332", "Title": "The relationship between bispectral index values and age in children", "title": "Bispectral index values during general anesthesia in children", "OutcomesAvailable": "No", "DateStart": "2011-03-10T00:00:00-06:00", "DateEnd": { "type": "actual", "value": "2012-05-01T00:00:00-05:00" }, "DateChangeLast": "2014-07-21T11:39:54-05:00", "gender": "N/A", "highAge": NumberInt(12), "lowAge": 0.5, "recordType": "xxxxxxxx", "__v": NumberInt(0) } Object containing key as document id and value as score ------------------------------------------------------- var textSearch = 'cancer'; var test_ids = { '277313', '278237', '278356', '278547' } scoresArr = { '277313': '79.06410256410257', '278237': '65.27777777777777', '278356': '66.83928571428572', '278547': '66.8051948051948' }
My request is where I want to add a rating from the above object to a new search.
var aggregation = TestCollection.aggregate( [{ $match: { $and: [ { "id": { $in : test_ids } }, { $text: {$search: textSearch} } ] } }, { $sort: { score: { $meta: "textScore" } } }, { $project: { id: 1, scoreText: { $meta: "textScore" }, score: { $add: [{ $cond: ["$scoreText", { $meta: "textScore" }, { $meta: "textScore" }] }, { $cond: [{ $gte: [scoresArr["$id"], 0] }, scoresArr["$id"], scoresArr["$id"] ]}, ] } } }, { $sort: { score: -1 } } ] ); aggregation.exec(function(err, data) {
I get a null result. I know I'm doing it wrong. Please help me solve this problem.
thanks