Search multiple keywords as 'AND' instead of 'OR'

This commit is contained in:
Shuqi 2023-11-13 03:44:33 +08:00
parent 5749093818
commit ef889cf928
1 changed files with 9 additions and 4 deletions

View File

@ -16,14 +16,19 @@ export const IconList = function () {
const keywords = query.toLowerCase().split(' ').filter(word => (word)) const keywords = query.toLowerCase().split(' ').filter(word => (word))
let filtered = []; let filtered = [];
for (const filename in iconData) { for (const filename in iconData) {
const matched = iconData[filename].filter(tag => { const matched = keywords.filter(keyword => {
for (const keyword of keywords) { for (const tag of iconData[filename]) {
if (tag.indexOf(keyword.toLowerCase()) != -1) return true 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) console.log(filtered)