diff --git a/install/package.json b/install/package.json index 7f75126df4..3d2e20db79 100644 --- a/install/package.json +++ b/install/package.json @@ -91,7 +91,7 @@ "multiparty": "4.2.3", "nconf": "0.12.0", "nodebb-plugin-2factor": "7.0.1", - "nodebb-plugin-composer-default": "10.0.40", + "nodebb-plugin-composer-default": "10.0.41", "nodebb-plugin-dbsearch": "6.0.0", "nodebb-plugin-emoji": "5.0.3", "nodebb-plugin-emoji-android": "4.0.0", diff --git a/public/openapi/read/search.yaml b/public/openapi/read/search.yaml index ed7cc5f621..6e36fc3891 100644 --- a/public/openapi/read/search.yaml +++ b/public/openapi/read/search.yaml @@ -23,8 +23,6 @@ get: type: boolean search_query: type: string - expandSearch: - type: boolean showAsPosts: type: boolean showAsTopics: diff --git a/public/src/modules/search.js b/public/src/modules/search.js index 5c4c32dc38..879fe274ae 100644 --- a/public/src/modules/search.js +++ b/public/src/modules/search.js @@ -238,7 +238,9 @@ define('search', ['translator', 'storage', 'hooks', 'alerts'], function (transla Search.api = function (data, callback) { const apiURL = config.relative_path + '/api/search?' + createQueryString(data); - data.searchOnly = undefined; + if (data.hasOwnProperty('searchOnly')) { + delete data.searchOnly; + } const searchURL = config.relative_path + '/search?' + createQueryString(data); $.get(apiURL, function (result) { result.url = searchURL; @@ -248,7 +250,6 @@ define('search', ['translator', 'storage', 'hooks', 'alerts'], function (transla function createQueryString(data) { const searchIn = data.in || 'titles'; - const postedBy = data.by || ''; let term = data.term.replace(/^[ ?#]*/, ''); try { term = encodeURIComponent(term); @@ -257,52 +258,11 @@ define('search', ['translator', 'storage', 'hooks', 'alerts'], function (transla } const query = { + ...data, term: term, in: searchIn, }; - if (data.matchWords) { - query.matchWords = data.matchWords; - } - - if (postedBy && postedBy.length && (searchIn === 'posts' || searchIn === 'titles' || searchIn === 'titlesposts')) { - query.by = postedBy; - } - - if (data.categories && data.categories.length) { - query.categories = data.categories; - if (data.searchChildren) { - query.searchChildren = data.searchChildren; - } - } - - if (data.hasTags && data.hasTags.length) { - query.hasTags = data.hasTags; - } - - if (parseInt(data.replies, 10) > 0) { - query.replies = data.replies; - query.repliesFilter = data.repliesFilter || 'atleast'; - } - - if (data.timeRange) { - query.timeRange = data.timeRange; - query.timeFilter = data.timeFilter || 'newer'; - } - - if (data.sortBy) { - query.sortBy = data.sortBy; - query.sortDirection = data.sortDirection; - } - - if (data.showAs) { - query.showAs = data.showAs; - } - - if (data.searchOnly) { - query.searchOnly = data.searchOnly; - } - hooks.fire('action:search.createQueryString', { query: query, data: data, diff --git a/src/controllers/search.js b/src/controllers/search.js index 96e2f33eca..3e694d4f1c 100644 --- a/src/controllers/search.js +++ b/src/controllers/search.js @@ -88,8 +88,6 @@ searchController.search = async function (req, res, next) { searchData.breadcrumbs = helpers.buildBreadcrumbs([{ text: '[[global:search]]' }]); - searchData.expandSearch = !req.query.term; - searchData.showAsPosts = !req.query.showAs || req.query.showAs === 'posts'; searchData.showAsTopics = req.query.showAs === 'topics'; searchData.title = '[[global:header.search]]'; @@ -148,25 +146,26 @@ const searches = {}; async function recordSearch(data) { const { query, searchIn } = data; - if (query) { - const cleanedQuery = String(query).trim().toLowerCase().slice(0, 255); - if (['titles', 'titlesposts', 'posts'].includes(searchIn) && cleanedQuery.length > 2) { - searches[data.uid] = searches[data.uid] || { timeoutId: 0, queries: [] }; - searches[data.uid].queries.push(cleanedQuery); - if (searches[data.uid].timeoutId) { - clearTimeout(searches[data.uid].timeoutId); - } - searches[data.uid].timeoutId = setTimeout(async () => { - if (searches[data.uid] && searches[data.uid].queries) { - const copy = searches[data.uid].queries.slice(); - const filtered = searches[data.uid].queries.filter( - q => !copy.find(query => query.startsWith(q) && query.length > q.length) - ); - delete searches[data.uid]; - await Promise.all(filtered.map(query => db.sortedSetIncrBy('searches:all', 1, query))); - } - }, 5000); + if (!query || parseInt(data.qs.composer, 10) === 1) { + return; + } + const cleanedQuery = String(query).trim().toLowerCase().slice(0, 255); + if (['titles', 'titlesposts', 'posts'].includes(searchIn) && cleanedQuery.length > 2) { + searches[data.uid] = searches[data.uid] || { timeoutId: 0, queries: [] }; + searches[data.uid].queries.push(cleanedQuery); + if (searches[data.uid].timeoutId) { + clearTimeout(searches[data.uid].timeoutId); } + searches[data.uid].timeoutId = setTimeout(async () => { + if (searches[data.uid] && searches[data.uid].queries) { + const copy = searches[data.uid].queries.slice(); + const filtered = searches[data.uid].queries.filter( + q => !copy.find(query => query.startsWith(q) && query.length > q.length) + ); + delete searches[data.uid]; + await Promise.all(filtered.map(query => db.sortedSetIncrBy('searches:all', 1, query))); + } + }, 5000); } }