Node.js based forum software built for the modern web
moved search to dbsearch
barisusaklidcbf53bae357
diff --git a/package.json b/package.jsonindex 0609a3dc22..fee26f6053 100644--- a/package.json+++ b/package.json@@ -56,7 +56,6 @@"passport": "^0.3.0","passport-local": "1.0.0","prompt": "^0.2.14",- "redisearch": "^0.0.6","request": "^2.44.0","rimraf": "~2.4.2","rss": "^1.0.0",diff --git a/src/database/mongo.js b/src/database/mongo.jsindex 0563e02633..5282024f6d 100644--- a/src/database/mongo.js+++ b/src/database/mongo.js@@ -124,7 +124,7 @@require('./mongo/sorted')(db, module);require('./mongo/list')(db, module);- if(nconf.get('mongo:password') && nconf.get('mongo:username')) {+ if (nconf.get('mongo:password') && nconf.get('mongo:username')) {db.authenticate(nconf.get('mongo:username'), nconf.get('mongo:password'), function (err) {if (err) {winston.error(err.stack);@@ -138,31 +138,22 @@}function createIndices() {- winston.info('[database] Checking database indices.')+ winston.info('[database] Checking database indices.');async.parallel([async.apply(createIndex, 'objects', {_key: 1, score: -1}, {background: true}),async.apply(createIndex, 'objects', {_key: 1, value: -1}, {background: true, unique: true, sparse: true}),-- async.apply(createIndex, 'objects', {expireAt: 1}, {expireAfterSeconds: 0, background: true}),-- async.apply(createIndex, 'searchtopic', {content: 'text', uid: 1, cid: 1}, {background: true}),- async.apply(createIndex, 'searchtopic', {id: 1}, {background: true}),-- async.apply(createIndex, 'searchpost', {content: 'text', uid: 1, cid: 1}, {background: true}),- async.apply(createIndex, 'searchpost', {id: 1}, {background: true})+ async.apply(createIndex, 'objects', {expireAt: 1}, {expireAfterSeconds: 0, background: true})], function(err) {- callback(err);- });- }-- function createIndex(collection, index, options, callback) {- db.collection(collection).ensureIndex(index, options, function(err) {if (err) {winston.error('Error creating index ' + err.message);}callback(err);});}++ function createIndex(collection, index, options, callback) {+ db.collection(collection).ensureIndex(index, options, callback);+ }});};diff --git a/src/database/mongo/main.js b/src/database/mongo/main.jsindex f09f13f173..777565df06 100644--- a/src/database/mongo/main.js+++ b/src/database/mongo/main.js@@ -5,83 +5,6 @@ var winston = require('winston');module.exports = function(db, module) {var helpers = module.helpers.mongo;- module.searchIndex = function(key, data, id, callback) {- callback = callback || function() {};- id = parseInt(id, 10);- if (!id) {- return callback();- }- var setData = {- id: id- };- for(var field in data) {- if (data.hasOwnProperty(field) && data[field]) {- setData[field] = data[field].toString();- }- }-- db.collection('search' + key).update({id: id}, {$set: setData}, {upsert:true, w: 1}, function(err) {- if (err) {- winston.error('Error indexing ' + err.message);- }- callback(err);- });- };-- module.search = function(key, data, limit, callback) {- var searchQuery = {};-- if (data.content) {- searchQuery.$text = {$search: data.content};- }-- if (Array.isArray(data.cid) && data.cid.length) {- data.cid = data.cid.filter(Boolean);- if (data.cid.length > 1) {- searchQuery.cid = {$in: data.cid.map(String)};- } else if (data.cid[0]) {- searchQuery.cid = data.cid[0].toString();- }- }-- if (Array.isArray(data.uid) && data.uid.length) {- data.uid = data.uid.filter(Boolean);- if (data.uid.length > 1) {- searchQuery.uid = {$in: data.uid.map(String)};- } else if (data.uid[0]) {- searchQuery.uid = data.uid[0].toString();- }- }-- db.collection('search' + key).find(searchQuery, {limit: limit, fields:{_id: 0, id: 1}}).toArray(function(err, results) {- if (err) {- return callback(err);- }-- if (!results || !results.length) {- return callback(null, []);- }-- var data = results.map(function(item) {- return item.id;- });-- callback(null, data);- });- };-- module.searchRemove = function(key, id, callback) {- callback = callback || helpers.noop;- id = parseInt(id, 10);- if (!id) {- return callback();- }-- db.collection('search' + key).remove({id: id}, function(err, res) {- callback(err);- });- };-module.flushdb = function(callback) {callback = callback || helpers.noop;db.dropDatabase(callback);diff --git a/src/database/redis.js b/src/database/redis.jsindex da9c49aaa6..239090aa95 100644--- a/src/database/redis.js+++ b/src/database/redis.js@@ -4,16 +4,11 @@var winston = require('winston'),nconf = require('nconf'),- path = require('path'),semver = require('semver'),session = require('express-session'),- utils = require('./../../public/src/utils.js'),redis,connectRedis,- redisSearch,- redisClient,- postSearch,- topicSearch;+ redisClient;module.questions = [{@@ -43,7 +38,6 @@try {redis = require('redis');connectRedis = require('connect-redis')(session);- redisSearch = require('redisearch');} catch (err) {winston.error('Unable to initialize Redis! Is Redis installed? Error :' + err.message);process.exit();@@ -58,9 +52,6 @@ttl: 60 * 60 * 24 * 14});- module.postSearch = redisSearch.createSearch('nodebbpostsearch', redisClient);- module.topicSearch = redisSearch.createSearch('nodebbtopicsearch', redisClient);-require('./redis/main')(redisClient, module);require('./redis/hash')(redisClient, module);require('./redis/sets')(redisClient, module);diff --git a/src/database/redis/main.js b/src/database/redis/main.jsindex 503d515569..7fc2890d87 100644--- a/src/database/redis/main.js+++ b/src/database/redis/main.js@@ -1,31 +1,6 @@"use strict";module.exports = function(redisClient, module) {- module.searchIndex = function(key, data, id, callback) {- var method = key === 'post' ? module.postSearch : module.topicSearch;-- method.index(data, id, function(err, res) {- callback(err);- });- };-- module.search = function(key, data, limit, callback) {- var method = key === 'post' ? module.postSearch : module.topicSearch;-- method.query(data, 0, limit - 1, callback);- };-- module.searchRemove = function(key, id, callback) {- callback = callback || function() {};- if (!id) {- return callback();- }- var method = key === 'post' ? module.postSearch : module.topicSearch;-- method.remove(id, function(err, res) {- callback(err);- });- };module.flushdb = function(callback) {redisClient.send_command('flushdb', [], function(err) {@@ -35,8 +10,6 @@ module.exports = function(redisClient, module) {});};--module.exists = function(key, callback) {redisClient.exists(key, function(err, exists) {callback(err, exists === 1);