From ee8e048015576a81b96df6fe57cd4308df24c5b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Mon, 25 Oct 2021 16:32:35 -0400 Subject: [PATCH] fix: move record to controller --- src/controllers/search.js | 9 +++++++++ src/search.js | 8 -------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/controllers/search.js b/src/controllers/search.js index 0dbdff2dd0..d45a7fbe47 100644 --- a/src/controllers/search.js +++ b/src/controllers/search.js @@ -66,6 +66,7 @@ searchController.search = async function (req, res, next) { const [searchData, categoriesData] = await Promise.all([ search.search(data), + recordSearch(data); buildCategories(req.uid, searchOnly), ]); @@ -95,6 +96,14 @@ searchController.search = async function (req, res, next) { res.render('search', searchData); }; +async function recordSearch(data) { + const { query, searchIn } = data; + const cleanedQuery = String(query).trim().toLowerCase().substr(0, 255); + if (['titles', 'titlesposts', 'posts'].includes(searchIn) && cleanedQuery.length > 2) { + await db.sortedSetIncrBy('searches:all', 1, cleanedQuery); + } +} + async function buildCategories(uid, searchOnly) { if (searchOnly) { return []; diff --git a/src/search.js b/src/search.js index f54181fb52..99fae633e8 100644 --- a/src/search.js +++ b/src/search.js @@ -45,7 +45,6 @@ async function searchInContent(data) { async function doSearch(type, searchIn) { if (searchIn.includes(data.searchIn)) { - await recordSearch(data.query); return await plugins.hooks.fire('filter:search.query', { index: type, content: data.query, @@ -95,13 +94,6 @@ async function searchInContent(data) { return Object.assign(returnData, metadata); } -async function recordSearch(query) { - const cleanedQuery = String(query).trim().toLowerCase().substr(0, 255); - if (cleanedQuery.length > 2) { - await db.sortedSetIncrBy('searches:all', 1, cleanedQuery); - } -} - async function filterAndSort(pids, data) { if (data.sortBy === 'relevance' && !data.replies && !data.timeRange && !data.hasTags && !plugins.hooks.hasListeners('filter:search.filterAndSort')) { return pids;