mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 11:35:55 +01:00
index topic titles too
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
var searchQuery = $('#topics-container').attr('data-search-query');
|
var searchQuery = $('#topics-container').attr('data-search-query');
|
||||||
|
|
||||||
$('.search-result-text').each(function(){
|
$('.search-result-text').each(function() {
|
||||||
var text = $(this).html();
|
var text = $(this).html();
|
||||||
var regex = new RegExp(searchQuery, 'gi');
|
var regex = new RegExp(searchQuery, 'gi');
|
||||||
text = text.replace(regex, '<span class="label label-success">'+searchQuery+'</span>');
|
text = text.replace(regex, '<span class="label label-success">'+searchQuery+'</span>');
|
||||||
|
|||||||
@@ -13,6 +13,21 @@
|
|||||||
<div class="category row">
|
<div class="category row">
|
||||||
<div class="span12">
|
<div class="span12">
|
||||||
<ul id="topics-container" data-search-query="{search_query}">
|
<ul id="topics-container" data-search-query="{search_query}">
|
||||||
|
<!-- BEGIN topics -->
|
||||||
|
<a href="../../topic/{topics.slug}" id="tid-{topics.tid}">
|
||||||
|
<li class="category-item">
|
||||||
|
<div class="row-fluid">
|
||||||
|
<div class="span12 img-polaroid">
|
||||||
|
<div class="search-result-post">
|
||||||
|
<img src="{topics.teaser_userpicture}" />
|
||||||
|
<strong>{topics.teaser_username}</strong>: <span class="search-result-text">{topics.title}</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
</a>
|
||||||
|
<!-- END topics -->
|
||||||
<!-- BEGIN posts -->
|
<!-- BEGIN posts -->
|
||||||
<a href="../../topic/{posts.topicSlug}#{posts.pid}" id="tid-{posts.tid}">
|
<a href="../../topic/{posts.topicSlug}#{posts.pid}" id="tid-{posts.tid}">
|
||||||
<li class="category-item">
|
<li class="category-item">
|
||||||
|
|||||||
@@ -8,7 +8,8 @@ var RDB = require('./redis.js'),
|
|||||||
utils = require('../public/src/utils'),
|
utils = require('../public/src/utils'),
|
||||||
plugins = require('./plugins'),
|
plugins = require('./plugins'),
|
||||||
reds = require('reds'),
|
reds = require('reds'),
|
||||||
search = reds.createSearch('nodebbsearch');
|
postSearch = reds.createSearch('nodebbpostsearch'),
|
||||||
|
topicSearch = reds.createSearch('nodebbtopicsearch');
|
||||||
|
|
||||||
(function(PostTools) {
|
(function(PostTools) {
|
||||||
PostTools.isMain = function(pid, tid, callback) {
|
PostTools.isMain = function(pid, tid, callback) {
|
||||||
@@ -58,14 +59,18 @@ var RDB = require('./redis.js'),
|
|||||||
posts.setPostField(pid, 'edited', Date.now());
|
posts.setPostField(pid, 'edited', Date.now());
|
||||||
posts.setPostField(pid, 'editor', uid);
|
posts.setPostField(pid, 'editor', uid);
|
||||||
|
|
||||||
search.remove(pid, function() {
|
postSearch.remove(pid, function() {
|
||||||
search.index(content, pid);
|
postSearch.index(content, pid);
|
||||||
});
|
});
|
||||||
|
|
||||||
posts.getPostField(pid, 'tid', function(tid) {
|
posts.getPostField(pid, 'tid', function(tid) {
|
||||||
PostTools.isMain(pid, tid, function(isMainPost) {
|
PostTools.isMain(pid, tid, function(isMainPost) {
|
||||||
if (isMainPost)
|
if (isMainPost) {
|
||||||
topics.setTopicField(tid, 'title', title);
|
topics.setTopicField(tid, 'title', title);
|
||||||
|
topicSearch.remove(tid, function() {
|
||||||
|
topicSearch.index(title, tid);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
io.sockets.in('topic_' + tid).emit('event:post_edited', {
|
io.sockets.in('topic_' + tid).emit('event:post_edited', {
|
||||||
pid: pid,
|
pid: pid,
|
||||||
@@ -90,7 +95,7 @@ var RDB = require('./redis.js'),
|
|||||||
var success = function() {
|
var success = function() {
|
||||||
posts.setPostField(pid, 'deleted', 1);
|
posts.setPostField(pid, 'deleted', 1);
|
||||||
|
|
||||||
search.remove(pid);
|
postSearch.remove(pid);
|
||||||
|
|
||||||
posts.getPostFields(pid, ['tid', 'uid'], function(postData) {
|
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);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ var RDB = require('./redis.js'),
|
|||||||
async = require('async'),
|
async = require('async'),
|
||||||
plugins = require('./plugins'),
|
plugins = require('./plugins'),
|
||||||
reds = require('reds'),
|
reds = require('reds'),
|
||||||
search = reds.createSearch('nodebbsearch');
|
postSearch = reds.createSearch('nodebbpostsearch');
|
||||||
|
|
||||||
(function(Posts) {
|
(function(Posts) {
|
||||||
|
|
||||||
@@ -337,7 +337,7 @@ var RDB = require('./redis.js'),
|
|||||||
|
|
||||||
plugins.fireHook('action:save_post_content', [pid, content]);
|
plugins.fireHook('action:save_post_content', [pid, content]);
|
||||||
|
|
||||||
search.index(content, pid);
|
postSearch.index(content, pid);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@@ -417,10 +417,10 @@ var RDB = require('./redis.js'),
|
|||||||
function reIndex(pid, callback) {
|
function reIndex(pid, callback) {
|
||||||
|
|
||||||
Posts.getPostField(pid, 'content', function(content) {
|
Posts.getPostField(pid, 'content', function(content) {
|
||||||
search.remove(pid, function() {
|
postSearch.remove(pid, function() {
|
||||||
|
|
||||||
if(content && content.length) {
|
if(content && content.length) {
|
||||||
search.index(content, pid);
|
postSearch.index(content, pid);
|
||||||
}
|
}
|
||||||
callback(null);
|
callback(null);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -158,24 +158,50 @@ var user = require('./../user.js'),
|
|||||||
app.get('/api/search/:term', function(req, res, next) {
|
app.get('/api/search/:term', function(req, res, next) {
|
||||||
|
|
||||||
var reds = require('reds');
|
var reds = require('reds');
|
||||||
var search = reds.createSearch('nodebbsearch');
|
var postSearch = reds.createSearch('nodebbpostsearch');
|
||||||
|
var topicSearch = reds.createSearch('nodebbtopicsearch');
|
||||||
|
|
||||||
search
|
function search(searchObj, callback) {
|
||||||
|
searchObj
|
||||||
.query(query = req.params.term).type('or')
|
.query(query = req.params.term).type('or')
|
||||||
.end(function(err, ids) {
|
.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)
|
if (err)
|
||||||
return next();
|
return next();
|
||||||
|
var noresults = !results[0].length && !results[1].length;
|
||||||
|
return res.json({
|
||||||
posts.getPostSummaryByPids(ids, function(posts) {
|
show_no_results: noresults?'show':'hide',
|
||||||
res.json(200, {
|
|
||||||
show_no_results:ids.length?'hide':'show',
|
|
||||||
search_query:req.params.term,
|
search_query:req.params.term,
|
||||||
posts:posts
|
posts:results[0],
|
||||||
|
topics:results[1]
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get('/api/404', function(req, res) {
|
app.get('/api/404', function(req, res) {
|
||||||
|
|||||||
@@ -4,7 +4,9 @@ var RDB = require('./redis.js'),
|
|||||||
user = require('./user.js'),
|
user = require('./user.js'),
|
||||||
async = require('async'),
|
async = require('async'),
|
||||||
notifications = require('./notifications.js'),
|
notifications = require('./notifications.js'),
|
||||||
posts = require('./posts');
|
posts = require('./posts'),
|
||||||
|
reds = require('reds'),
|
||||||
|
topicSearch = reds.createSearch('nodebbtopicsearch');
|
||||||
|
|
||||||
(function(ThreadTools) {
|
(function(ThreadTools) {
|
||||||
|
|
||||||
@@ -88,6 +90,8 @@ var RDB = require('./redis.js'),
|
|||||||
topics.setTopicField(tid, 'deleted', 1);
|
topics.setTopicField(tid, 'deleted', 1);
|
||||||
ThreadTools.lock(tid, uid);
|
ThreadTools.lock(tid, uid);
|
||||||
|
|
||||||
|
topicSearch.remove(tid);
|
||||||
|
|
||||||
io.sockets.in('topic_' + tid).emit('event:topic_deleted', {
|
io.sockets.in('topic_' + tid).emit('event:topic_deleted', {
|
||||||
tid: tid,
|
tid: tid,
|
||||||
status: 'ok'
|
status: 'ok'
|
||||||
@@ -116,6 +120,10 @@ var RDB = require('./redis.js'),
|
|||||||
tid: tid
|
tid: tid
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
topics.getTopicField(tid, 'title', function(title) {
|
||||||
|
topicSearch.index(title, tid);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,9 @@ var RDB = require('./redis.js')
|
|||||||
postTools = require('./postTools'),
|
postTools = require('./postTools'),
|
||||||
async = require('async'),
|
async = require('async'),
|
||||||
feed = require('./feed.js'),
|
feed = require('./feed.js'),
|
||||||
favourites = require('./favourites.js');
|
favourites = require('./favourites.js'),
|
||||||
|
reds = require('reds'),
|
||||||
|
topicSearch = reds.createSearch('nodebbtopicsearch');
|
||||||
|
|
||||||
marked.setOptions({
|
marked.setOptions({
|
||||||
breaks: true
|
breaks: true
|
||||||
@@ -597,6 +599,7 @@ marked.setOptions({
|
|||||||
'pinned': 0
|
'pinned': 0
|
||||||
});
|
});
|
||||||
|
|
||||||
|
topicSearch.index(title, tid);
|
||||||
RDB.set('topicslug:' + slug + ':tid', tid);
|
RDB.set('topicslug:' + slug + ':tid', tid);
|
||||||
|
|
||||||
posts.create(uid, tid, content, images, function(postData) {
|
posts.create(uid, tid, content, images, function(postData) {
|
||||||
|
|||||||
Reference in New Issue
Block a user