mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 20:16:04 +01:00
search in mongo
This commit is contained in:
@@ -25,6 +25,13 @@
|
||||
});
|
||||
|
||||
|
||||
// TODO : what is the db user name??
|
||||
/*if(nconf.get('mongo:password')) {
|
||||
db.authenticate(dbUser, nconf.get('mongo:password'), function (err) {
|
||||
});
|
||||
}*/
|
||||
|
||||
|
||||
db.createCollection('objects', function(err, collection) {
|
||||
if(err) {
|
||||
winston.error("Error creating collection " + err.message);
|
||||
@@ -56,11 +63,7 @@
|
||||
callback(err);
|
||||
});
|
||||
|
||||
// look up how its done in mongo
|
||||
/*if (nconf.get('mongo:password')) {
|
||||
redisClient.auth(nconf.get('mongo:password'));
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -69,22 +72,44 @@
|
||||
//
|
||||
|
||||
module.searchIndex = function(key, content, id) {
|
||||
// REQUIRES MONGO 2.4
|
||||
db.collection('search').update({key:key, content:content, _id:id}, {upsert:true, w: 1}, function(err, result) {
|
||||
|
||||
var data = {
|
||||
id:id,
|
||||
key:key,
|
||||
content:content
|
||||
};
|
||||
|
||||
db.collection('search').update({id:id, key:key}, {$set:data}, {upsert:true, w: 1}, function(err, result) {
|
||||
if(err) {
|
||||
winston.error('Error indexing ' + err.message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
module.search = function(key, term, callback) {
|
||||
// REQUIRES MONGO 2.4
|
||||
db.command({text:"search" , search: term }, function(err, result) {
|
||||
callback(err, result)
|
||||
|
||||
db.command({text:"search" , search: term, filter: {key:key} }, function(err, result) {
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
if(!result) {
|
||||
return callback(null, []);
|
||||
}
|
||||
|
||||
if(result.results && result.results.length) {
|
||||
var data = result.results.map(function(item) {
|
||||
return item.obj.id;
|
||||
});
|
||||
callback(null, data);
|
||||
} else {
|
||||
callback(null, []);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
module.searchRemove = function(key, id) {
|
||||
// REQUIRES MONGO 2.4
|
||||
db.collection('search').remove({_id:id}, function(err, result) {
|
||||
db.collection('search').remove({id:id, key:key}, function(err, result) {
|
||||
callback(err, result);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@
|
||||
module.search = function(key, term, callback) {
|
||||
function search(searchObj, callback) {
|
||||
searchObj
|
||||
.query(query = term).type('or')
|
||||
.query(term).type('or')
|
||||
.end(callback);
|
||||
}
|
||||
|
||||
|
||||
@@ -219,7 +219,6 @@ var async = require('async'),
|
||||
async.each(defaults, function (configObj, next) {
|
||||
meta.configs.setOnEmpty(configObj.field, configObj.value, next);
|
||||
}, function (err) {
|
||||
console.log('calling meta.configs.init');
|
||||
meta.configs.init(next);
|
||||
});
|
||||
},
|
||||
|
||||
@@ -407,10 +407,11 @@ var DebugRoute = function(app) {
|
||||
|
||||
var miscTests = [
|
||||
function(next) {
|
||||
//db.searchIndex('post', 'here is content tomato testing purple orange', 1);
|
||||
/*db.searchIndex('post', 'green tomato is healthy', 2);
|
||||
next();*/
|
||||
db.search('post', 'tomato', function(err, result) {
|
||||
next(err, result);
|
||||
})
|
||||
});
|
||||
|
||||
}
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user