From ef889cf928f0343ae38231f97d61c239b8ad6b27 Mon Sep 17 00:00:00 2001 From: Shuqi Date: Mon, 13 Nov 2023 03:44:33 +0800 Subject: [PATCH] Search multiple keywords as 'AND' instead of 'OR' --- src/IconList.jsx | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/IconList.jsx b/src/IconList.jsx index 10acedb..d4c4ea4 100644 --- a/src/IconList.jsx +++ b/src/IconList.jsx @@ -16,14 +16,19 @@ export const IconList = function () { const keywords = query.toLowerCase().split(' ').filter(word => (word)) let filtered = []; for (const filename in iconData) { - const matched = iconData[filename].filter(tag => { - for (const keyword of keywords) { + const matched = keywords.filter(keyword => { + for (const tag of iconData[filename]) { if (tag.indexOf(keyword.toLowerCase()) != -1) return true } - return false }) + // const matched = iconData[filename].filter(tag => { + // for (const keyword of keywords) { + // if (tag.indexOf(keyword.toLowerCase()) != -1) return true + // } + // return false + // }) - if (matched.length) filtered.push(filename) + if (matched.length == keywords.length) filtered.push(filename) } console.log(filtered)