From 6cfaea06f03c04676c86e847bcc27fcb7c032af9 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 22:06:28 -0400 Subject: [PATCH] fix: undefined query showing in searches --- src/controllers/search.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/controllers/search.js b/src/controllers/search.js index 906277f8ba..76a34d1e39 100644 --- a/src/controllers/search.js +++ b/src/controllers/search.js @@ -99,9 +99,11 @@ searchController.search = async function (req, res, next) { 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); + if (query) { + 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); + } } }