diff --git a/public/language/en-GB/admin/settings/general.json b/public/language/en-GB/admin/settings/general.json index c26740ee4f..72ecfe641f 100644 --- a/public/language/en-GB/admin/settings/general.json +++ b/public/language/en-GB/admin/settings/general.json @@ -26,5 +26,6 @@ "touch-icon.upload": "Upload", "touch-icon.help": "Recommended size and format: 192x192, PNG format only. If no touch icon is specified, NodeBB will fall back to using the favicon.", "outgoing-links": "Outgoing Links", - "outgoing-links.warning-page": "Use Outgoing Links Warning Page" + "outgoing-links.warning-page": "Use Outgoing Links Warning Page", + "search-default-sort-by": "Search default sort by" } \ No newline at end of file diff --git a/public/language/en-GB/search.json b/public/language/en-GB/search.json index 98c1afcea2..51a0a76ebb 100644 --- a/public/language/en-GB/search.json +++ b/public/language/en-GB/search.json @@ -12,6 +12,7 @@ "reply-count": "Reply Count", "at-least": "At least", "at-most": "At most", + "relevance": "Relevance", "post-time": "Post time", "newer-than": "Newer than", "older-than": "Older than", diff --git a/public/src/client/search.js b/public/src/client/search.js index 48cf358c0c..28a9ac94cd 100644 --- a/public/src/client/search.js +++ b/public/src/client/search.js @@ -105,8 +105,8 @@ define('forum/search', ['search', 'autocomplete'], function (searchModule, autoc $('#post-time-filter').val(formData.timeFilter); } - if (formData.sortBy) { - $('#post-sort-by').val(formData.sortBy); + if (formData.sortBy || ajaxify.data.searchDefaultSortBy) { + $('#post-sort-by').val(formData.sortBy || ajaxify.data.searchDefaultSortBy); $('#post-sort-direction').val(formData.sortDirection); } diff --git a/src/controllers/search.js b/src/controllers/search.js index 2261e4f3b7..db3adf0682 100644 --- a/src/controllers/search.js +++ b/src/controllers/search.js @@ -38,7 +38,7 @@ searchController.search = function (req, res, next) { repliesFilter: req.query.repliesFilter, timeRange: req.query.timeRange, timeFilter: req.query.timeFilter, - sortBy: req.query.sortBy, + sortBy: req.query.sortBy || meta.config.searchDefaultSortBy || '', sortDirection: req.query.sortDirection, page: page, uid: req.uid, @@ -67,6 +67,7 @@ searchController.search = function (req, res, next) { searchData.title = '[[global:header.search]]'; searchData.breadcrumbs = helpers.buildBreadcrumbs([{text: '[[global:search]]'}]); searchData.expandSearch = !req.query.term; + searchData.searchDefaultSortBy = meta.config.searchDefaultSortBy || ''; res.render('search', searchData); }); diff --git a/src/search.js b/src/search.js index d77b1f58f0..bd1fde947d 100644 --- a/src/search.js +++ b/src/search.js @@ -147,7 +147,7 @@ function getMatchedPosts(pids, data, callback) { topicFields.push('postcount'); } - if (data.sortBy) { + if (data.sortBy && data.sortBy !== 'relevance') { if (data.sortBy.startsWith('category')) { topicFields.push('cid'); } else if (data.sortBy.startsWith('topic.')) { @@ -328,7 +328,7 @@ function filterByTags(posts, hasTags) { } function sortPosts(posts, data) { - if (!posts.length || !data.sortBy) { + if (!posts.length || !data.sortBy || data.sortBy === 'relevance') { return; } diff --git a/src/views/admin/settings/general.tpl b/src/views/admin/settings/general.tpl index 990509e41f..68705951da 100644 --- a/src/views/admin/settings/general.tpl +++ b/src/views/admin/settings/general.tpl @@ -113,6 +113,23 @@ +