modified indices, removed key 2 collections now

v1.18.x
barisusakli 10 years ago
parent ec7caea368
commit 518aec6e76

@ -110,10 +110,14 @@
createIndex('objects', {_key: 1, value: -1}, {background:true}); createIndex('objects', {_key: 1, value: -1}, {background:true});
createIndex('objects', {expireAt: 1}, {expireAfterSeconds:0, 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('searchtopic', {content: 'text', uid: 1, cid: 1}, {background:true});
createIndex('search', {cid: 1}, {background:true}); createIndex('searchtopic', {id: 1}, {background:true});
createIndex('search', {uid: 1}, {background:true});
createIndex('searchpost', {content: 'text', uid: 1, cid: 1}, {background:true});
createIndex('searchpost', {id: 1}, {background:true});
if (typeof callback === 'function') { if (typeof callback === 'function') {
callback(); callback();

@ -8,8 +8,7 @@ module.exports = function(db, module) {
module.searchIndex = function(key, data, id, callback) { module.searchIndex = function(key, data, id, callback) {
callback = callback || function() {}; callback = callback || function() {};
var setData = { var setData = {
id: id, id: id
key: key
}; };
for(var field in data) { for(var field in data) {
if (data.hasOwnProperty(field) && data[field]) { 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) { if(err) {
winston.error('Error indexing ' + err.message); winston.error('Error indexing ' + err.message);
} }
@ -26,9 +25,7 @@ module.exports = function(db, module) {
}; };
module.search = function(key, data, limit, callback) { module.search = function(key, data, limit, callback) {
var searchQuery = { var searchQuery = {};
key: key
};
if (data.content) { if (data.content) {
searchQuery.$text = {$search: 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) { if (err) {
return callback(err); return callback(err);
} }
@ -72,7 +69,7 @@ module.exports = function(db, module) {
if (!id) { if (!id) {
return callback(); 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); callback(err);
}); });
}; };

Loading…
Cancel
Save