mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-01-06 15:42:52 +01:00
Merge branch 'master' of https://github.com/designcreateplay/NodeBB
This commit is contained in:
@@ -76,9 +76,11 @@
|
||||
</li>
|
||||
<!-- ENDIF isAdmin -->
|
||||
|
||||
<!-- IF searchEnabled -->
|
||||
<li class="visible-xs">
|
||||
<a id="mobile-search-button" href="{relative_path}/search"><i class="fa fa-search fa-fw" title="[[global:header.search]]"></i> [[global:header.search]]</a>
|
||||
</li>
|
||||
<!-- ENDIF searchEnabled -->
|
||||
|
||||
<!-- BEGIN navigation -->
|
||||
<li class="{navigation.class}">
|
||||
@@ -167,6 +169,7 @@
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<!-- IF searchEnabled -->
|
||||
<ul id="logged-conditional-menu" class="nav navbar-nav navbar-right">
|
||||
<li>
|
||||
<form id="search-form" class="navbar-form navbar-right hidden-xs" role="search" method="GET" action="">
|
||||
@@ -180,6 +183,7 @@
|
||||
</form>
|
||||
</li>
|
||||
</ul>
|
||||
<!-- ENDIF searchEnabled -->
|
||||
|
||||
<ul class="nav navbar-nav navbar-right pagination-block hide">
|
||||
<li class="active">
|
||||
|
||||
@@ -112,53 +112,6 @@
|
||||
// Exported functions
|
||||
//
|
||||
|
||||
module.searchIndex = function(key, content, id) {
|
||||
|
||||
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, limit, callback) {
|
||||
db.command({text:"search" , search: term, filter: {key:key}, limit: limit }, 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, callback) {
|
||||
db.collection('search').remove({id:id, key:key}, function(err, result) {
|
||||
if(err) {
|
||||
winston.error('Error removing search ' + err.message);
|
||||
}
|
||||
if (typeof callback === 'function') {
|
||||
callback();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
module.flushdb = function(callback) {
|
||||
db.dropDatabase(function(err, result) {
|
||||
if(err){
|
||||
|
||||
@@ -9,13 +9,11 @@
|
||||
utils = require('./../../public/src/utils.js'),
|
||||
redis,
|
||||
connectRedis,
|
||||
reds,
|
||||
redisClient;
|
||||
|
||||
try {
|
||||
redis = require('redis');
|
||||
connectRedis = require('connect-redis')(express);
|
||||
reds = require('reds');
|
||||
} catch (err) {
|
||||
winston.error('Unable to initialize Redis! Is Redis installed? Error :' + err.message);
|
||||
process.exit();
|
||||
@@ -49,14 +47,6 @@
|
||||
ttl: 60 * 60 * 24 * 14
|
||||
});
|
||||
|
||||
reds.createClient = function () {
|
||||
return reds.client || (reds.client = redisClient);
|
||||
};
|
||||
|
||||
var userSearch = reds.createSearch('nodebbusersearch'),
|
||||
postSearch = reds.createSearch('nodebbpostsearch'),
|
||||
topicSearch = reds.createSearch('nodebbtopicsearch');
|
||||
|
||||
var db = parseInt(nconf.get('redis:database'), 10);
|
||||
|
||||
if (db){
|
||||
@@ -75,47 +65,6 @@
|
||||
//
|
||||
// Exported functions
|
||||
//
|
||||
module.searchIndex = function(key, content, id) {
|
||||
if(key === 'post') {
|
||||
postSearch.index(content, id);
|
||||
} else if(key === 'topic') {
|
||||
topicSearch.index(content, id);
|
||||
} else if(key === 'user') {
|
||||
userSearch.index(content, id);
|
||||
}
|
||||
}
|
||||
|
||||
module.search = function(key, term, limit, callback) {
|
||||
function search(searchObj, callback) {
|
||||
searchObj
|
||||
.query(term)
|
||||
.between(0, limit - 1)
|
||||
.type('or')
|
||||
.end(callback);
|
||||
}
|
||||
|
||||
if(key === 'post') {
|
||||
search(postSearch, callback);
|
||||
} else if(key === 'topic') {
|
||||
search(topicSearch, callback);
|
||||
} else if(key === 'user') {
|
||||
search(userSearch, callback);
|
||||
}
|
||||
}
|
||||
|
||||
module.searchRemove = function(key, id, callback) {
|
||||
if(key === 'post') {
|
||||
postSearch.remove(id);
|
||||
} else if(key === 'topic') {
|
||||
topicSearch.remove(id);
|
||||
} else if(key === 'user') {
|
||||
userSearch.remove(id);
|
||||
}
|
||||
|
||||
if (typeof callback === 'function') {
|
||||
callback()
|
||||
}
|
||||
}
|
||||
|
||||
module.flushdb = function(callback) {
|
||||
redisClient.send_command('flushdb', [], function(err) {
|
||||
|
||||
@@ -75,10 +75,6 @@ var winston = require('winston'),
|
||||
|
||||
events.logPostEdit(uid, pid);
|
||||
|
||||
db.searchRemove('post', pid, function() {
|
||||
db.searchIndex('post', content, pid);
|
||||
});
|
||||
|
||||
async.parallel([
|
||||
function(next) {
|
||||
posts.getPostField(pid, 'tid', function(err, tid) {
|
||||
@@ -89,12 +85,12 @@ var winston = require('winston'),
|
||||
|
||||
topics.setTopicField(tid, 'title', title);
|
||||
topics.setTopicField(tid, 'slug', slug);
|
||||
|
||||
db.searchRemove('topic', tid, function() {
|
||||
db.searchIndex('topic', title, tid);
|
||||
});
|
||||
}
|
||||
|
||||
posts.getPostData(pid, function(err, postData) {
|
||||
plugins.fireHook('action:post.edit', postData);
|
||||
});
|
||||
|
||||
next(null, {
|
||||
tid: tid,
|
||||
isMainPost: isMainPost
|
||||
@@ -129,7 +125,8 @@ var winston = require('winston'),
|
||||
var success = function() {
|
||||
posts.setPostField(pid, 'deleted', 1);
|
||||
db.decrObjectField('global', 'postCount');
|
||||
db.searchRemove('post', pid);
|
||||
|
||||
plugins.fireHook('action:post.delete', pid);
|
||||
|
||||
events.logPostDelete(uid, pid);
|
||||
|
||||
@@ -205,7 +202,7 @@ var winston = require('winston'),
|
||||
});
|
||||
|
||||
|
||||
db.searchIndex('post', postData.content, pid);
|
||||
plugins.fireHook('action:post.restore', postData);
|
||||
|
||||
// Restore topic if it is the only post
|
||||
topics.getTopicField(postData.tid, 'postcount', function(err, count) {
|
||||
|
||||
24
src/posts.js
24
src/posts.js
@@ -87,8 +87,6 @@ var db = require('./database'),
|
||||
|
||||
plugins.fireHook('action:post.save', postData);
|
||||
|
||||
db.searchIndex('post', content, postData.pid);
|
||||
|
||||
next(null, postData);
|
||||
});
|
||||
}
|
||||
@@ -447,28 +445,6 @@ var db = require('./database'),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Posts.reIndexPids = function(pids, callback) {
|
||||
|
||||
function reIndex(pid, next) {
|
||||
|
||||
Posts.getPostField(pid, 'content', function(err, content) {
|
||||
if(err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
db.searchRemove('post', pid, function() {
|
||||
if (content && content.length) {
|
||||
db.searchIndex('post', content, pid);
|
||||
}
|
||||
next();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async.each(pids, reIndex, callback);
|
||||
}
|
||||
|
||||
// this function should really be called User.getFavouritePosts
|
||||
Posts.getFavourites = function(uid, start, end, callback) {
|
||||
db.getSortedSetRevRange('uid:' + uid + ':favourites', start, end, function(err, pids) {
|
||||
|
||||
@@ -361,10 +361,17 @@ var path = require('path'),
|
||||
});
|
||||
|
||||
app.get('/search/:term', function (req, res, next) {
|
||||
if (!Plugins.hasListeners('filter:search.query')) {
|
||||
return res.redirect('/404');
|
||||
}
|
||||
|
||||
var limit = 50;
|
||||
|
||||
function searchPosts(callback) {
|
||||
db.search('post', req.params.term, limit, function(err, pids) {
|
||||
Plugins.fireHook('filter:search.query', {
|
||||
index: 'post',
|
||||
query: req.params.terms
|
||||
}, function(err, pids) {
|
||||
if (err) {
|
||||
return callback(err, null);
|
||||
}
|
||||
@@ -374,7 +381,10 @@ var path = require('path'),
|
||||
}
|
||||
|
||||
function searchTopics(callback) {
|
||||
db.search('topic', req.params.term, limit, function(err, tids) {
|
||||
Plugins.fireHook('filter:search.query', {
|
||||
index: 'topic',
|
||||
query: req.params.terms
|
||||
}, function(err, tids) {
|
||||
if (err) {
|
||||
return callback(err, null);
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@ var DebugRoute = function(app) {
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
app.get('/cid/:cid', function (req, res) {
|
||||
categories.getCategoryData(req.params.cid, function (err, data) {
|
||||
if (data) {
|
||||
@@ -55,24 +54,6 @@ var DebugRoute = function(app) {
|
||||
});
|
||||
});
|
||||
|
||||
app.get('/groups/prune', function(req, res) {
|
||||
var Groups = require('../groups');
|
||||
|
||||
Groups.prune(function(err) {
|
||||
res.send('pruned');
|
||||
});
|
||||
});
|
||||
|
||||
app.get('/reindex', function (req, res) {
|
||||
topics.reIndexAll(function (err) {
|
||||
if (err) {
|
||||
return res.json(err);
|
||||
} else {
|
||||
res.send('Topics and users reindexed');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
app.get('/test', function(req, res) {
|
||||
// categories.getModerators(1, function(err, mods) {
|
||||
// res.json(mods);
|
||||
|
||||
@@ -11,7 +11,8 @@ var winston = require('winston'),
|
||||
posts = require('./posts'),
|
||||
meta = require('./meta'),
|
||||
websockets = require('./socket.io'),
|
||||
events = require('./events');
|
||||
events = require('./events'),
|
||||
Plugins = require('./plugins');
|
||||
|
||||
|
||||
(function(ThreadTools) {
|
||||
@@ -76,7 +77,7 @@ var winston = require('winston'),
|
||||
|
||||
ThreadTools.lock(tid);
|
||||
|
||||
db.searchRemove('topic', tid);
|
||||
Plugins.fireHook('action:topic.delete', tid);
|
||||
|
||||
events.logTopicDelete(uid, tid);
|
||||
|
||||
@@ -120,9 +121,7 @@ var winston = require('winston'),
|
||||
tid: tid
|
||||
});
|
||||
|
||||
topics.getTopicField(tid, 'title', function(err, title) {
|
||||
db.searchIndex('topic', title, tid);
|
||||
});
|
||||
Plugins.fireHook('action:topic.restore', tid);
|
||||
|
||||
callback(null, {
|
||||
tid:tid
|
||||
|
||||
@@ -16,7 +16,8 @@ var async = require('async'),
|
||||
postTools = require('./postTools'),
|
||||
notifications = require('./notifications'),
|
||||
favourites = require('./favourites'),
|
||||
meta = require('./meta');
|
||||
meta = require('./meta'),
|
||||
Plugins = require('./plugins');
|
||||
|
||||
(function(Topics) {
|
||||
|
||||
@@ -48,7 +49,7 @@ var async = require('async'),
|
||||
}
|
||||
|
||||
db.sortedSetAdd('topics:tid', timestamp, tid);
|
||||
db.searchIndex('topic', title, tid);
|
||||
Plugins.fireHook('action:topic.save', tid);
|
||||
|
||||
user.addTopicIdToUser(uid, tid, timestamp);
|
||||
|
||||
@@ -1209,25 +1210,4 @@ var async = require('async'),
|
||||
], callback);
|
||||
});
|
||||
};
|
||||
|
||||
Topics.reIndexTopic = function(tid, callback) {
|
||||
Topics.getPids(tid, function(err, pids) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
posts.reIndexPids(pids, callback);
|
||||
});
|
||||
}
|
||||
|
||||
Topics.reIndexAll = function(callback) {
|
||||
db.getSortedSetRange('topics:tid', 0, -1, function(err, tids) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
async.each(tids, Topics.reIndexTopic, callback);
|
||||
});
|
||||
}
|
||||
|
||||
}(exports));
|
||||
|
||||
@@ -104,7 +104,8 @@ module.exports.server = server;
|
||||
clientScripts: clientScripts,
|
||||
navigation: custom_header.navigation,
|
||||
'cache-buster': meta.config['cache-buster'] ? 'v=' + meta.config['cache-buster'] : '',
|
||||
allowRegistration: meta.config.allowRegistration === undefined || parseInt(meta.config.allowRegistration, 10) === 1
|
||||
allowRegistration: meta.config.allowRegistration === undefined || parseInt(meta.config.allowRegistration, 10) === 1,
|
||||
searchEnabled: plugins.hasListeners('filter:search.query') ? true : false
|
||||
},
|
||||
escapeList = {
|
||||
'&': '&',
|
||||
|
||||
Reference in New Issue
Block a user