add matchwords to search api

v1.18.x
Barış Soner Uşaklı 7 years ago
parent 60f8870b72
commit 749b282cdd

@ -64,7 +64,7 @@
"mubsub": "^1.4.0",
"nconf": "^0.9.1",
"nodebb-plugin-composer-default": "6.0.17",
"nodebb-plugin-dbsearch": "2.0.11",
"nodebb-plugin-dbsearch": "2.0.12",
"nodebb-plugin-emoji": "^2.2.0",
"nodebb-plugin-emoji-android": "2.0.0",
"nodebb-plugin-markdown": "8.4.2",
@ -73,9 +73,9 @@
"nodebb-plugin-spam-be-gone": "0.5.3",
"nodebb-rewards-essentials": "0.0.11",
"nodebb-theme-lavender": "5.0.4",
"nodebb-theme-persona": "8.0.5",
"nodebb-theme-persona": "8.0.6",
"nodebb-theme-slick": "1.2.0",
"nodebb-theme-vanilla": "9.0.3",
"nodebb-theme-vanilla": "9.0.4",
"nodebb-widget-essentials": "4.0.2",
"nodemailer": "4.4.1",
"passport": "^0.4.0",

@ -5,6 +5,9 @@
"in": "In",
"titles": "Titles",
"titles-posts": "Titles and Posts",
"match-words": "Match words",
"all": "All",
"any": "Any",
"posted-by": "Posted by",
"in-categories": "In Categories",
"search-child-categories": "Search child categories",

@ -37,6 +37,7 @@ define('forum/search', ['search', 'autocomplete', 'storage'], function (searchMo
};
searchData.term = $('#search-input').val();
if (searchData.in === 'posts' || searchData.in === 'titlesposts' || searchData.in === 'titles') {
searchData.matchWords = form.find('#match-words-filter').val();
searchData.by = form.find('#posted-by-user').val();
searchData.categories = form.find('#posted-in-categories').val();
searchData.searchChildren = form.find('#search-children').is(':checked');
@ -79,6 +80,10 @@ define('forum/search', ['search', 'autocomplete', 'storage'], function (searchMo
updateFormItemVisiblity(formData.in);
}
if (formData.matchWords) {
$('#match-words-filter').val(formData.matchWords);
}
if (formData.by) {
$('#posted-by-user').val(formData.by);
}

@ -41,6 +41,10 @@ define('search', ['navigator', 'translator', 'storage'], function (nav, translat
in: searchIn,
};
if (data.matchWords) {
query.matchWords = data.matchWords;
}
if (postedBy && (searchIn === 'posts' || searchIn === 'titles' || searchIn === 'titlesposts')) {
query.by = postedBy;
}

@ -30,6 +30,7 @@ searchController.search = function (req, res, next) {
var data = {
query: req.query.term,
searchIn: req.query.in || 'posts',
matchWords: req.query.matchWords || 'all',
postedBy: req.query.by,
categories: req.query.categories,
searchChildren: req.query.searchChildren,

@ -56,8 +56,14 @@ function searchInContent(data, callback) {
},
function (results, next) {
function doSearch(type, searchIn, next) {
if (searchIn.indexOf(data.searchIn) !== -1) {
search.searchQuery(type, data.query, results.searchCids, results.searchUids, next);
if (searchIn.includes(data.searchIn)) {
plugins.fireHook('filter:search.query', {
index: type,
content: data.query,
matchWords: data.matchWords || 'all',
cid: results.searchCids,
uid: results.searchUids,
}, next);
} else {
next(null, []);
}
@ -430,13 +436,3 @@ function getSearchUids(data, callback) {
callback(null, []);
}
}
search.searchQuery = function (index, content, cids, uids, callback) {
plugins.fireHook('filter:search.query', {
index: index,
content: content,
cid: cids,
uid: uids,
}, callback);
};

@ -76,6 +76,7 @@ module.exports = function (Topics) {
search.search({
query: topicData.title,
searchIn: 'titles',
matchWords: 'any',
categories: [topicData.cid],
uid: uid,
page: 1,

Loading…
Cancel
Save