Node.js based forum software built for the modern web
add matchwords to search api
Barış Soner Uşaklı749b282cdd1a
diff --git a/install/package.json b/install/package.jsonindex 7a88ccfde0..01ec9d73b4 100644--- a/install/package.json+++ b/install/package.json@@ -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",diff --git a/public/language/en-GB/search.json b/public/language/en-GB/search.jsonindex 51a0a76ebb..35f9c40625 100644--- a/public/language/en-GB/search.json+++ b/public/language/en-GB/search.json@@ -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",diff --git a/public/src/client/search.js b/public/src/client/search.jsindex 38a34fc818..ccc10f8f8f 100644--- a/public/src/client/search.js+++ b/public/src/client/search.js@@ -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 (searchMoupdateFormItemVisiblity(formData.in);}+ if (formData.matchWords) {+ $('#match-words-filter').val(formData.matchWords);+ }+if (formData.by) {$('#posted-by-user').val(formData.by);}diff --git a/public/src/modules/search.js b/public/src/modules/search.jsindex daf9fae820..bcab5d1142 100644--- a/public/src/modules/search.js+++ b/public/src/modules/search.js@@ -41,6 +41,10 @@ define('search', ['navigator', 'translator', 'storage'], function (nav, translatin: searchIn,};+ if (data.matchWords) {+ query.matchWords = data.matchWords;+ }+if (postedBy && (searchIn === 'posts' || searchIn === 'titles' || searchIn === 'titlesposts')) {query.by = postedBy;}diff --git a/src/controllers/search.js b/src/controllers/search.jsindex 4c37b6258d..4032357ffd 100644--- a/src/controllers/search.js+++ b/src/controllers/search.js@@ -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,diff --git a/src/search.js b/src/search.jsindex 893731d473..f0726f60d6 100644--- a/src/search.js+++ b/src/search.js@@ -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);-};-diff --git a/src/topics/suggested.js b/src/topics/suggested.jsindex 0d7947e4d4..187af3706a 100644--- a/src/topics/suggested.js+++ b/src/topics/suggested.js@@ -76,6 +76,7 @@ module.exports = function (Topics) {search.search({query: topicData.title,searchIn: 'titles',+ matchWords: 'any',categories: [topicData.cid],uid: uid,page: 1,