diff --git a/public/src/forum/search.js b/public/src/forum/search.js
index 9412915cc7..c21baec1e6 100644
--- a/public/src/forum/search.js
+++ b/public/src/forum/search.js
@@ -3,7 +3,7 @@
$(document).ready(function() {
var searchQuery = $('#topics-container').attr('data-search-query');
- $('.search-result-text').each(function(){
+ $('.search-result-text').each(function() {
var text = $(this).html();
var regex = new RegExp(searchQuery, 'gi');
text = text.replace(regex, ''+searchQuery+'');
diff --git a/public/templates/search.tpl b/public/templates/search.tpl
index c08f82e7c5..7dec88da87 100644
--- a/public/templates/search.tpl
+++ b/public/templates/search.tpl
@@ -13,6 +13,21 @@
+
+
+ -
+
+
+
+

+
{topics.teaser_username}:
{topics.title}
+
+
+
+
+
+
+
-
diff --git a/src/postTools.js b/src/postTools.js
index 0f826ec995..9d4418607f 100644
--- a/src/postTools.js
+++ b/src/postTools.js
@@ -8,7 +8,8 @@ var RDB = require('./redis.js'),
utils = require('../public/src/utils'),
plugins = require('./plugins'),
reds = require('reds'),
- search = reds.createSearch('nodebbsearch');
+ postSearch = reds.createSearch('nodebbpostsearch'),
+ topicSearch = reds.createSearch('nodebbtopicsearch');
(function(PostTools) {
PostTools.isMain = function(pid, tid, callback) {
@@ -58,14 +59,18 @@ var RDB = require('./redis.js'),
posts.setPostField(pid, 'edited', Date.now());
posts.setPostField(pid, 'editor', uid);
- search.remove(pid, function() {
- search.index(content, pid);
+ postSearch.remove(pid, function() {
+ postSearch.index(content, pid);
});
posts.getPostField(pid, 'tid', function(tid) {
PostTools.isMain(pid, tid, function(isMainPost) {
- if (isMainPost)
+ if (isMainPost) {
topics.setTopicField(tid, 'title', title);
+ topicSearch.remove(tid, function() {
+ topicSearch.index(title, tid);
+ });
+ }
io.sockets.in('topic_' + tid).emit('event:post_edited', {
pid: pid,
@@ -90,7 +95,7 @@ var RDB = require('./redis.js'),
var success = function() {
posts.setPostField(pid, 'deleted', 1);
- search.remove(pid);
+ postSearch.remove(pid);
posts.getPostFields(pid, ['tid', 'uid'], function(postData) {
@@ -140,7 +145,7 @@ var RDB = require('./redis.js'),
});
});
- search.index(postData.content, pid);
+ postSearch.index(postData.content, pid);
});
};
diff --git a/src/posts.js b/src/posts.js
index 8219a39363..583ab16236 100644
--- a/src/posts.js
+++ b/src/posts.js
@@ -10,7 +10,7 @@ var RDB = require('./redis.js'),
async = require('async'),
plugins = require('./plugins'),
reds = require('reds'),
- search = reds.createSearch('nodebbsearch');
+ postSearch = reds.createSearch('nodebbpostsearch');
(function(Posts) {
@@ -337,7 +337,7 @@ var RDB = require('./redis.js'),
plugins.fireHook('action:save_post_content', [pid, content]);
- search.index(content, pid);
+ postSearch.index(content, pid);
});
});
} else {
@@ -417,10 +417,10 @@ var RDB = require('./redis.js'),
function reIndex(pid, callback) {
Posts.getPostField(pid, 'content', function(content) {
- search.remove(pid, function() {
+ postSearch.remove(pid, function() {
if(content && content.length) {
- search.index(content, pid);
+ postSearch.index(content, pid);
}
callback(null);
});
diff --git a/src/routes/api.js b/src/routes/api.js
index bb64ce1ba7..4e8182d4a6 100644
--- a/src/routes/api.js
+++ b/src/routes/api.js
@@ -158,24 +158,50 @@ var user = require('./../user.js'),
app.get('/api/search/:term', function(req, res, next) {
var reds = require('reds');
- var search = reds.createSearch('nodebbsearch');
-
- search
- .query(query = req.params.term).type('or')
- .end(function(err, ids) {
- if (err)
- return next();
-
-
- posts.getPostSummaryByPids(ids, function(posts) {
- res.json(200, {
- show_no_results:ids.length?'hide':'show',
- search_query:req.params.term,
- posts:posts
- });
+ var postSearch = reds.createSearch('nodebbpostsearch');
+ var topicSearch = reds.createSearch('nodebbtopicsearch');
+
+ function search(searchObj, callback) {
+ searchObj
+ .query(query = req.params.term).type('or')
+ .end(callback);
+ }
+
+ function searchPosts(callback) {
+ search(postSearch, function(err, pids) {
+ if(err)
+ return callback(err, null);
+
+ posts.getPostSummaryByPids(pids, function(posts) {
+ callback(null, posts);
});
-
+ })
+ }
+
+ function searchTopics(callback) {
+ search(topicSearch, function(err, tids) {
+ if(err)
+ return callback(err, null);
+ console.log(tids);
+ topics.getTopicsByTids(tids, 0, function(topics) {
+ callback(null, topics);
+ }, 0);
});
+ }
+
+ async.parallel([searchPosts, searchTopics], function(err, results) {
+ if (err)
+ return next();
+ var noresults = !results[0].length && !results[1].length;
+ return res.json({
+ show_no_results: noresults?'show':'hide',
+ search_query:req.params.term,
+ posts:results[0],
+ topics:results[1]
+ });
+ });
+
+
});
app.get('/api/404', function(req, res) {
diff --git a/src/threadTools.js b/src/threadTools.js
index 6083741846..2d2068574a 100644
--- a/src/threadTools.js
+++ b/src/threadTools.js
@@ -4,7 +4,9 @@ var RDB = require('./redis.js'),
user = require('./user.js'),
async = require('async'),
notifications = require('./notifications.js'),
- posts = require('./posts');
+ posts = require('./posts'),
+ reds = require('reds'),
+ topicSearch = reds.createSearch('nodebbtopicsearch');
(function(ThreadTools) {
@@ -88,6 +90,8 @@ var RDB = require('./redis.js'),
topics.setTopicField(tid, 'deleted', 1);
ThreadTools.lock(tid, uid);
+ topicSearch.remove(tid);
+
io.sockets.in('topic_' + tid).emit('event:topic_deleted', {
tid: tid,
status: 'ok'
@@ -116,6 +120,10 @@ var RDB = require('./redis.js'),
tid: tid
});
}
+
+ topics.getTopicField(tid, 'title', function(title) {
+ topicSearch.index(title, tid);
+ });
}
});
}
diff --git a/src/topics.js b/src/topics.js
index bbbf812751..5e37392556 100644
--- a/src/topics.js
+++ b/src/topics.js
@@ -10,7 +10,9 @@ var RDB = require('./redis.js')
postTools = require('./postTools'),
async = require('async'),
feed = require('./feed.js'),
- favourites = require('./favourites.js');
+ favourites = require('./favourites.js'),
+ reds = require('reds'),
+ topicSearch = reds.createSearch('nodebbtopicsearch');
marked.setOptions({
breaks: true
@@ -574,7 +576,7 @@ marked.setOptions({
// Global Topics
if (uid == null) uid = 0;
if (uid !== null) {
- RDB.sadd('topics:tid', tid);
+ RDB.sadd('topics:tid', tid);
} else {
// need to add some unique key sent by client so we can update this with the real uid later
RDB.lpush(schema.topics().queued_tids, tid);
@@ -597,6 +599,7 @@ marked.setOptions({
'pinned': 0
});
+ topicSearch.index(title, tid);
RDB.set('topicslug:' + slug + ':tid', tid);
posts.create(uid, tid, content, images, function(postData) {