Skip to content
This repository has been archived by the owner on Jun 22, 2022. It is now read-only.

🔎 Now able to search using multiple words separated by space. #90

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 28 additions & 7 deletions app/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,38 @@ function search (query) {
if (query.length === 0 || (query.length === 1 && query.charCodeAt() <= 255)) {
results = emojikeys.slice(0)
} else {
var resultsDict = {}
indexKeys.forEach(function matchQuery (keyword) {
if (stringIncludes(keyword, query)) {
index[keyword].forEach(function addMatchingEmoji (emoji) {
resultsDict[emoji] = true
})
var resultsDict = null
let words = query.split(/\s+/)
for(let i in words) {
let word = words[i]
if (word === '') continue

let wordResultsDict = {}
indexKeys.forEach(function matchQuery (keyword) {
if (stringIncludes(keyword, word)) {
index[keyword].forEach(function addMatchingEmoji (emoji) {
wordResultsDict[emoji] = true
})
}
})

if (resultsDict === null) {
// Just initialize it.
resultsDict = wordResultsDict
} else {
// Intersect with existing results.
for(let emoji in resultsDict) {
if (!wordResultsDict.hasOwnProperty(emoji)) {
delete resultsDict[emoji]
}
}
}
})
}

results = Object.keys(resultsDict).sort(function sortResults (a, b) {
return emojikeyIndexTable[a] - emojikeyIndexTable[b]
})

}

// Put exact match first
Expand Down