Basic search functionality on the frontpage, I want to add support for
more advanced searches like using boolean operators, but right now it's pretty basic.
This commit is contained in:
@@ -202,9 +202,12 @@ router.post("/submit_edit_post", (req,res) => {
|
||||
|
||||
router.get('/search', (req, res) => {
|
||||
const search_term = req.query.q; // 'q' is the parameter name
|
||||
let search_type = req.query.type; // eg 'any', 'post', 'user' etc...
|
||||
if (typeof search_type == 'undefined') { // Default to 'any'
|
||||
search_type = 'any';
|
||||
let search_type = req.query.type; // eg 'post', 'user'
|
||||
if (typeof search_type == 'string') { // Make the search_term an array
|
||||
search_type = [ search_type ]
|
||||
}
|
||||
if (typeof search_type == 'undefined') { // Default to all of the types
|
||||
search_type = ['user', 'post'];
|
||||
}
|
||||
console.log('searching for: ', search_term);
|
||||
const search_results = data.searchdata(search_term, search_type); // data.searchdata returns an array of search results
|
||||
@@ -213,6 +216,8 @@ router.get('/search', (req, res) => {
|
||||
config,
|
||||
locale,
|
||||
search_results,
|
||||
search_term,
|
||||
search_type,
|
||||
})
|
||||
|
||||
}); // /search
|
||||
|
||||
Reference in New Issue
Block a user