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,
"categoriesPerPage": 50,
"userSearchResultsPerPage": 50,
"searchDefaultSortBy": "relevance",
"searchDefaultIn": "titlesposts",
"searchDefaultInQuick": "titles",
"maximumGroupNameLength": 255,
"maximumGroupTitleLength": 40,
"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.",
"outgoing-links": "Outgoing Links",
"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",
"site-colors": "Site Color Metadata",
"theme-color": "Theme Color",

@ -483,7 +483,7 @@ app.cacheBuster = null;
return;
}
/* 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 inputEl = options.searchElements.inputEl;
var searchTimeoutId = 0;
@ -608,7 +608,7 @@ app.cacheBuster = null;
};
app.handleSearch = function (searchOptions) {
searchOptions = searchOptions || { in: 'titles' };
searchOptions = searchOptions || { in: config.searchDefaultInQuick || 'titles' };
var searchButton = $('#search-button');
var searchFields = $('#search-fields');
var searchInput = $('#search-fields input');

@ -81,7 +81,7 @@ define('forum/search', [
if (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);
updateFormItemVisiblity(formData.in);

@ -64,6 +64,7 @@ apiController.loadConfig = async function (req) {
categoryTopicSort: meta.config.categoryTopicSort || 'newest_to_oldest',
csrf_token: req.uid >= 0 && req.csrfToken && req.csrfToken(),
searchEnabled: plugins.hooks.hasListeners('filter:search.query'),
searchDefaultInQuick: meta.config.searchDefaultInQuick || 'titles',
bootswatchSkin: meta.config.bootswatchSkin || '',
enablePostHistory: meta.config.enablePostHistory === 1,
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: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']) ||
(req.query.in === 'tags' && userPrivileges['search:tags']) ||
(req.query.in === 'categories') ||
@ -89,6 +89,7 @@ searchController.search = async function (req, res, next) {
searchData.title = '[[global:header.search]]';
searchData.searchDefaultSortBy = meta.config.searchDefaultSortBy || '';
searchData.searchDefaultIn = meta.config.searchDefaultIn || 'titlesposts';
searchData.privileges = userPrivileges;
res.render('search', searchData);

@ -136,8 +136,29 @@
</div>
<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="form-group">
<label>[[admin/settings/general:search-default-in]]</label>
<select class="form-control" data-field="searchDefaultIn">
<option value="titlesposts">[[search:titles-posts]]</option>
<option value="titles">[[search:titles]]</option>
<option value="posts">[[global:posts]]</option>
<option value="categories">[[global:header.categories]]</option>
<option value="users">[[global:users]]</option>
<option value="tags">[[tags:tags]]</option>
</select>
</div>
<div class="form-group">
<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>
@ -152,6 +173,7 @@
<option value="category.name">[[search:category]]</option>
</select>
</div>
</div>
</div>
<div class="row">

Loading…
Cancel
Save