mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 03:26:04 +01:00
index topic titles too
This commit is contained in:
@@ -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, '<span class="label label-success">'+searchQuery+'</span>');
|
||||
|
||||
@@ -13,6 +13,21 @@
|
||||
<div class="category row">
|
||||
<div class="span12">
|
||||
<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 -->
|
||||
<a href="../../topic/{posts.topicSlug}#{posts.pid}" id="tid-{posts.tid}">
|
||||
<li class="category-item">
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user