From 518aec6e76180078269bb17ffb56af880d58f9bd Mon Sep 17 00:00:00 2001 From: barisusakli Date: Sun, 15 Mar 2015 03:18:24 -0400 Subject: [PATCH] modified indices, removed key 2 collections now --- src/database/mongo.js | 12 ++++++++---- src/database/mongo/main.js | 13 +++++-------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/database/mongo.js b/src/database/mongo.js index 9e4399b031..f97eeb6651 100644 --- a/src/database/mongo.js +++ b/src/database/mongo.js @@ -110,10 +110,14 @@ createIndex('objects', {_key: 1, value: -1}, {background:true}); createIndex('objects', {expireAt: 1}, {expireAfterSeconds:0, background:true}); - createIndex('search', {content:'text'}, {background:true}); - createIndex('search', {key: 1, id: 1}, {background:true}); - createIndex('search', {cid: 1}, {background:true}); - createIndex('search', {uid: 1}, {background:true}); + + createIndex('searchtopic', {content: 'text', uid: 1, cid: 1}, {background:true}); + createIndex('searchtopic', {id: 1}, {background:true}); + + + createIndex('searchpost', {content: 'text', uid: 1, cid: 1}, {background:true}); + createIndex('searchpost', {id: 1}, {background:true}); + if (typeof callback === 'function') { callback(); diff --git a/src/database/mongo/main.js b/src/database/mongo/main.js index 469a9720d9..5e027843e0 100644 --- a/src/database/mongo/main.js +++ b/src/database/mongo/main.js @@ -8,8 +8,7 @@ module.exports = function(db, module) { module.searchIndex = function(key, data, id, callback) { callback = callback || function() {}; var setData = { - id: id, - key: key + id: id }; for(var field in data) { if (data.hasOwnProperty(field) && data[field]) { @@ -17,7 +16,7 @@ module.exports = function(db, module) { } } - db.collection('search').update({key: key, id: id}, {$set: setData}, {upsert:true, w: 1}, function(err) { + db.collection('search' + key).update({id: id}, {$set: setData}, {upsert:true, w: 1}, function(err) { if(err) { winston.error('Error indexing ' + err.message); } @@ -26,9 +25,7 @@ module.exports = function(db, module) { }; module.search = function(key, data, limit, callback) { - var searchQuery = { - key: key - }; + var searchQuery = {}; if (data.content) { searchQuery.$text = {$search: data.content}; @@ -50,7 +47,7 @@ module.exports = function(db, module) { } } - db.collection('search').find(searchQuery, {limit: limit}).toArray(function(err, results) { + db.collection('search' + key).find(searchQuery, {limit: limit}).toArray(function(err, results) { if (err) { return callback(err); } @@ -72,7 +69,7 @@ module.exports = function(db, module) { if (!id) { return callback(); } - db.collection('search').remove({key: key, id: id}, function(err, res) { + db.collection('search' + key).remove({id: id}, function(err, res) { callback(err); }); };