full text search using reds, issue #142

This commit is contained in:
Baris Soner Usakli
2013-08-03 20:54:16 -04:00
parent 797d05a84a
commit d6b9a2799b
10 changed files with 179 additions and 42 deletions

View File

@@ -146,5 +146,36 @@ var user = require('./../user.js'),
res.redirect(global.nconf.get('relative_path') + '/404');
}
});
app.get('/api/search', function(req, res) {
return res.json({
show_no_results:'hide',
search_query:'',
posts:[]
});
});
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
});
});
});
});
}
}(exports));