絵文字ピッカーでAND検索に対応

This commit is contained in:
syuilo 2020-11-07 21:28:28 +09:00
parent 30c9c3739f
commit 80c490a18b

View file

@ -190,36 +190,58 @@ export default defineComponent({
const exactMatch = emojis.find(e => e.name === q); const exactMatch = emojis.find(e => e.name === q);
if (exactMatch) matches.add(exactMatch); if (exactMatch) matches.add(exactMatch);
for (const emoji of emojis) { if (q.includes(' ')) { // AND
if (emoji.name.startsWith(q)) { const keywords = q.split(' ');
matches.add(emoji);
if (matches.size >= max) break;
}
}
if (matches.size >= max) return matches;
for (const emoji of emojis) { //
if (emoji.aliases.some(alias => alias.startsWith(q))) { for (const emoji of emojis) {
matches.add(emoji); if (keywords.every(keyword => emoji.name.includes(keyword))) {
if (matches.size >= max) break; matches.add(emoji);
if (matches.size >= max) break;
}
} }
} if (matches.size >= max) return matches;
if (matches.size >= max) return matches;
for (const emoji of emojis) { //
if (emoji.name.includes(q)) { for (const emoji of emojis) {
matches.add(emoji); if (keywords.every(keyword => emoji.name.includes(keyword) || emoji.aliases.some(alias => alias.includes(keyword)))) {
if (matches.size >= max) break; matches.add(emoji);
if (matches.size >= max) break;
}
} }
} } else {
if (matches.size >= max) return matches; for (const emoji of emojis) {
if (emoji.name.startsWith(q)) {
matches.add(emoji);
if (matches.size >= max) break;
}
}
if (matches.size >= max) return matches;
for (const emoji of emojis) { for (const emoji of emojis) {
if (emoji.aliases.some(alias => alias.includes(q))) { if (emoji.aliases.some(alias => alias.startsWith(q))) {
matches.add(emoji); matches.add(emoji);
if (matches.size >= max) break; if (matches.size >= max) break;
}
}
if (matches.size >= max) return matches;
for (const emoji of emojis) {
if (emoji.name.includes(q)) {
matches.add(emoji);
if (matches.size >= max) break;
}
}
if (matches.size >= max) return matches;
for (const emoji of emojis) {
if (emoji.aliases.some(alias => alias.includes(q))) {
matches.add(emoji);
if (matches.size >= max) break;
}
} }
} }
return matches; return matches;
}; };
@ -231,36 +253,58 @@ export default defineComponent({
const exactMatch = emojis.find(e => e.name === q); const exactMatch = emojis.find(e => e.name === q);
if (exactMatch) matches.add(exactMatch); if (exactMatch) matches.add(exactMatch);
for (const emoji of emojis) { if (q.includes(' ')) { // AND
if (emoji.name.startsWith(q)) { const keywords = q.split(' ');
matches.add(emoji);
if (matches.size >= max) break;
}
}
if (matches.size >= max) return matches;
for (const emoji of emojis) { //
if (emoji.keywords.some(keyword => keyword.startsWith(q))) { for (const emoji of emojis) {
matches.add(emoji); if (keywords.every(keyword => emoji.name.includes(keyword))) {
if (matches.size >= max) break; matches.add(emoji);
if (matches.size >= max) break;
}
} }
} if (matches.size >= max) return matches;
if (matches.size >= max) return matches;
for (const emoji of emojis) { //
if (emoji.name.includes(q)) { for (const emoji of emojis) {
matches.add(emoji); if (keywords.every(keyword => emoji.name.includes(keyword) || emoji.keywords.some(alias => alias.includes(keyword)))) {
if (matches.size >= max) break; matches.add(emoji);
if (matches.size >= max) break;
}
} }
} } else {
if (matches.size >= max) return matches; for (const emoji of emojis) {
if (emoji.name.startsWith(q)) {
matches.add(emoji);
if (matches.size >= max) break;
}
}
if (matches.size >= max) return matches;
for (const emoji of emojis) { for (const emoji of emojis) {
if (emoji.keywords.some(keyword => keyword.includes(q))) { if (emoji.keywords.some(keyword => keyword.startsWith(q))) {
matches.add(emoji); matches.add(emoji);
if (matches.size >= max) break; if (matches.size >= max) break;
}
}
if (matches.size >= max) return matches;
for (const emoji of emojis) {
if (emoji.name.includes(q)) {
matches.add(emoji);
if (matches.size >= max) break;
}
}
if (matches.size >= max) return matches;
for (const emoji of emojis) {
if (emoji.keywords.some(keyword => keyword.includes(q))) {
matches.add(emoji);
if (matches.size >= max) break;
}
} }
} }
return matches; return matches;
}; };