feat: allow changing default search in

v1.18.x
Barış Soner Uşaklı 3 years ago
parent 116f9cb55e
commit 794bf01b21

@ -107,6 +107,9 @@
"postsPerPage": 20, "postsPerPage": 20,
"categoriesPerPage": 50, "categoriesPerPage": 50,
"userSearchResultsPerPage": 50, "userSearchResultsPerPage": 50,
"searchDefaultSortBy": "relevance",
"searchDefaultIn": "titlesposts",
"searchDefaultInQuick": "titles",
"maximumGroupNameLength": 255, "maximumGroupNameLength": 255,
"maximumGroupTitleLength": 40, "maximumGroupTitleLength": 40,
"preventTopicDeleteAfterReplies": 0, "preventTopicDeleteAfterReplies": 0,

@ -35,7 +35,10 @@
"maskable-icon.help": "Recommended size and format: 512x512, PNG format only. If no maskable icon is specified, NodeBB will fall back to the Touch Icon.", "maskable-icon.help": "Recommended size and format: 512x512, PNG format only. If no maskable icon is specified, NodeBB will fall back to the Touch Icon.",
"outgoing-links": "Outgoing Links", "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", "search": "Search",
"search-default-in": "Search In",
"search-default-in-quick": "Quick Search In",
"search-default-sort-by": "Sort by",
"outgoing-links.whitelist": "Domains to whitelist for bypassing the warning page", "outgoing-links.whitelist": "Domains to whitelist for bypassing the warning page",
"site-colors": "Site Color Metadata", "site-colors": "Site Color Metadata",
"theme-color": "Theme Color", "theme-color": "Theme Color",

@ -483,7 +483,7 @@ app.cacheBuster = null;
return; return;
} }
/* eslint-disable-next-line */ /* eslint-disable-next-line */
var searchOptions = Object.assign({ in: 'titles' }, options.searchOptions); var searchOptions = Object.assign({ in: config.searchDefaultInQuick || 'titles' }, options.searchOptions);
var quickSearchResults = options.searchElements.resultEl; var quickSearchResults = options.searchElements.resultEl;
var inputEl = options.searchElements.inputEl; var inputEl = options.searchElements.inputEl;
var searchTimeoutId = 0; var searchTimeoutId = 0;
@ -608,7 +608,7 @@ app.cacheBuster = null;
}; };
app.handleSearch = function (searchOptions) { app.handleSearch = function (searchOptions) {
searchOptions = searchOptions || { in: 'titles' }; searchOptions = searchOptions || { in: config.searchDefaultInQuick || 'titles' };
var searchButton = $('#search-button'); var searchButton = $('#search-button');
var searchFields = $('#search-fields'); var searchFields = $('#search-fields');
var searchInput = $('#search-fields input'); var searchInput = $('#search-fields input');

@ -81,7 +81,7 @@ define('forum/search', [
if (ajaxify.data.term) { if (ajaxify.data.term) {
$('#search-input').val(ajaxify.data.term); $('#search-input').val(ajaxify.data.term);
} }
formData.in = formData.in || 'posts'; formData.in = formData.in || ajaxify.data.searchDefaultIn;
$('#search-in').val(formData.in); $('#search-in').val(formData.in);
updateFormItemVisiblity(formData.in); updateFormItemVisiblity(formData.in);

@ -64,6 +64,7 @@ apiController.loadConfig = async function (req) {
categoryTopicSort: meta.config.categoryTopicSort || 'newest_to_oldest', categoryTopicSort: meta.config.categoryTopicSort || 'newest_to_oldest',
csrf_token: req.uid >= 0 && req.csrfToken && req.csrfToken(), csrf_token: req.uid >= 0 && req.csrfToken && req.csrfToken(),
searchEnabled: plugins.hooks.hasListeners('filter:search.query'), searchEnabled: plugins.hooks.hasListeners('filter:search.query'),
searchDefaultInQuick: meta.config.searchDefaultInQuick || 'titles',
bootswatchSkin: meta.config.bootswatchSkin || '', bootswatchSkin: meta.config.bootswatchSkin || '',
enablePostHistory: meta.config.enablePostHistory === 1, enablePostHistory: meta.config.enablePostHistory === 1,
timeagoCutoff: meta.config.timeagoCutoff !== '' ? Math.max(0, parseInt(meta.config.timeagoCutoff, 10)) : meta.config.timeagoCutoff, timeagoCutoff: meta.config.timeagoCutoff !== '' ? Math.max(0, parseInt(meta.config.timeagoCutoff, 10)) : meta.config.timeagoCutoff,

@ -27,7 +27,7 @@ searchController.search = async function (req, res, next) {
'search:content': privileges.global.can('search:content', req.uid), 'search:content': privileges.global.can('search:content', req.uid),
'search:tags': privileges.global.can('search:tags', req.uid), 'search:tags': privileges.global.can('search:tags', req.uid),
}); });
req.query.in = req.query.in || 'posts'; req.query.in = req.query.in || meta.config.searchDefaultIn || 'titlesposts';
const allowed = (req.query.in === 'users' && userPrivileges['search:users']) || const allowed = (req.query.in === 'users' && userPrivileges['search:users']) ||
(req.query.in === 'tags' && userPrivileges['search:tags']) || (req.query.in === 'tags' && userPrivileges['search:tags']) ||
(req.query.in === 'categories') || (req.query.in === 'categories') ||
@ -89,6 +89,7 @@ searchController.search = async function (req, res, next) {
searchData.title = '[[global:header.search]]'; searchData.title = '[[global:header.search]]';
searchData.searchDefaultSortBy = meta.config.searchDefaultSortBy || ''; searchData.searchDefaultSortBy = meta.config.searchDefaultSortBy || '';
searchData.searchDefaultIn = meta.config.searchDefaultIn || 'titlesposts';
searchData.privileges = userPrivileges; searchData.privileges = userPrivileges;
res.render('search', searchData); res.render('search', searchData);

@ -136,21 +136,43 @@
</div> </div>
<div class="row"> <div class="row">
<div class="col-sm-2 col-xs-12 settings-header">[[admin/settings/general:search-default-sort-by]]</div> <div class="col-sm-2 col-xs-12 settings-header">[[admin/settings/general:search]]</div>
<div class="col-sm-10 col-xs-12"> <div class="col-sm-10 col-xs-12">
<select id="post-sort-by" class="form-control" data-field="searchDefaultSortBy"> <div class="form-group">
<option value="relevance">[[search:relevance]]</option> <label>[[admin/settings/general:search-default-in]]</label>
<option value="timestamp">[[search:post-time]]</option> <select class="form-control" data-field="searchDefaultIn">
<option value="votes">[[search:votes]]</option> <option value="titlesposts">[[search:titles-posts]]</option>
<option value="topic.lastposttime">[[search:last-reply-time]]</option> <option value="titles">[[search:titles]]</option>
<option value="topic.title">[[search:topic-title]]</option> <option value="posts">[[global:posts]]</option>
<option value="topic.postcount">[[search:number-of-replies]]</option> <option value="categories">[[global:header.categories]]</option>
<option value="topic.viewcount">[[search:number-of-views]]</option> <option value="users">[[global:users]]</option>
<option value="topic.votes">[[search:topic-votes]]</option> <option value="tags">[[tags:tags]]</option>
<option value="topic.timestamp">[[search:topic-start-date]]</option> </select>
<option value="user.username">[[search:username]]</option> </div>
<option value="category.name">[[search:category]]</option> <div class="form-group">
</select> <label>[[admin/settings/general:search-default-in-quick]]</label>
<select class="form-control" data-field="searchDefaultInQuick">
<option value="titlesposts">[[search:titles-posts]]</option>
<option value="titles">[[search:titles]]</option>
<option value="posts">[[global:posts]]</option>
</select>
</div>
<div class="form-group">
<label>[[admin/settings/general:search-default-sort-by]]</label>
<select id="post-sort-by" class="form-control" data-field="searchDefaultSortBy">
<option value="relevance">[[search:relevance]]</option>
<option value="timestamp">[[search:post-time]]</option>
<option value="votes">[[search:votes]]</option>
<option value="topic.lastposttime">[[search:last-reply-time]]</option>
<option value="topic.title">[[search:topic-title]]</option>
<option value="topic.postcount">[[search:number-of-replies]]</option>
<option value="topic.viewcount">[[search:number-of-views]]</option>
<option value="topic.votes">[[search:topic-votes]]</option>
<option value="topic.timestamp">[[search:topic-start-date]]</option>
<option value="user.username">[[search:username]]</option>
<option value="category.name">[[search:category]]</option>
</select>
</div>
</div> </div>
</div> </div>

Loading…
Cancel
Save