Update Emoji Picker Search to use Trie Search#14212
Conversation
|
@mananjadhav @Luke9389 One of you needs to copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
|
Starting to review this. |
|
@stitesExpensify How is the search supposed to work? We have this emoji: and if I search by the |
|
Hm playing with this even more, I think our trie might not be building correctly, or the search method itself is broken. Prod (with expected results) 2023-01-11_11-17-58.mp4This branch ( 2023-01-11_11-18-17.mp4 |
|
@stitesExpensify Ops, this regex missing Screen.Recording.2023-01-12.at.6.47.53.PM.movI'm working on the order issue now. |
|
For the order issue, we should use +++ b/src/libs/EmojiUtils.js
@@ -228,7 +228,7 @@ function suggestEmojis(text, limit = 5) {
if (matching.length === limit) {
return matching;
}
- matching.unshift({code: nodes[j].metaData.code, name: nodes[j].name});
+ matching.push({code: nodes[j].metaData.code, name: nodes[j].name});
}
const suggestions = nodes[j].metaData.suggestions;
for (let i = 0; i < suggestions.length; i++) {
@@ -236,7 +236,7 @@ function suggestEmojis(text, limit = 5) {
return matching;
}
if (!_.find(matching, obj => obj.name === suggestions[i].name)) {
- matching.unshift(suggestions[i]);
+ matching.push(suggestions[i]);
}
}
}+++ b/src/libs/Trie/index.js
@@ -102,7 +102,7 @@ class Trie {
return matching;
}
if (node.isEndOfWord) {
- matching.unshift({name: prefix, metaData: node.metaData});
+ matching.push({name: prefix, metaData: node.metaData});
}
const children = _.keys(node.children);
for (let i = 0; i < children.length; i++) {Screen.Recording.2023-01-12.at.7.47.23.PM.mov |
|
@Karim-30 I made those changes and did not get the expected results. The regex change allowed searching Additionally, using |
|
@stitesExpensify getAllMatchingWords missing the const nodes = emojisTrie.getAllMatchingWords(emojiData[0].toLowerCase().slice(1), limit);webb-2023-01-13_09.11.04.mp4
It work without this sorting webb-2023-01-13_09.11.57.mp4 |
|
@stitesExpensify Is it ready for the next round of review and testing? |
|
@mananjadhav not quite. @Karim-30 I just pushed my changes, am I missing something? I'm still getting the wrong order. |
|
In my understanding of the data structure, we won't always find emojis in the same order as they appear in the main list right? That would only happen if they were alphabetically listed? |
|
Swapping only one to push, and not the other fixed it for |
|
Updated and ready for review! |
|
@stitesExpensify The If you insert
|
Reviewer Checklist
Screenshots/VideosWebweb-emoji-trie-search.movMobile Web - Chromemweb-chrome-emoji-trie-search.movMobile Web - Safarimweb-safari-emoji-trie-search.movDesktopdesktop-emoji-trie-search.moviOSios-emoji-trie-search.movAndroidandroid-emoji-trie-search.movThanks @stitesExpensify and @Karim-30 for the changes here. These test well now and faster too. I've completed the checklist and attached the screencasts for all platforms (while for search only Web and Desktop are relevant). @Luke9389 @roryabraham All yours to merge. |
Performance Comparison Report 📊Significant Changes To DurationThere are no entries Meaningless Changes To DurationShow entries
Show details
|
|
🚀 Deployed to staging by @roryabraham in version: 1.2.56-0 🚀
|
|
🚀 Deployed to production by https://github.com/AndrewGable in version: 1.2.56-0 🚀
|


cc @roryabraham since you were heavily involved in the initial creation of the trie search
Details
This PR changes the emoji picker search to use the Trie Search which is much more efficient.
Unfortunately, the results are not in the same order as the initial list, so they don't show up how you would expect. To fix this, I gave each emoji an index so that regardless of which order the search returns them in, we can put them back in the right order.
Fixed Issues
$ https://github.com/Expensify/Expensify/issues/239099
PROPOSAL: N/A
Tests
Web and Desktop Only:
WRONG
RIGHT

All Platforms:
:smile:Offline tests
This is not reliant on any API requests, so offline tests are not needed
QA Steps
Web and Desktop Only:
WRONG
RIGHT

All Platforms:
:smile:PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectiontoggleReportand notonIconClick)src/languages/*files and using the translation methodWaiting for Copylabel for a copy review on the original GH to get the correct copy.STYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)/** comment above it */thisproperly so there are no scoping issues (i.e. foronClick={this.submit}the methodthis.submitshould be bound tothisin the constructor)thisare necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);ifthis.submitis never passed to a component event handler likeonClick)StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG)Avataris modified, I verified thatAvataris working as expected in all cases)ScrollViewcomponent to make it scrollable when more elements are added to the page.Screenshots/Videos
Web
2023-01-10_16-17-19.mp4
Mobile Web - Chrome
2023-01-10_16-10-37.mp4
Mobile Web - Safari
2023-01-10_15-57-07.mp4
Desktop
2023-01-10_16-18-13.mp4
iOS
2023-01-10_15-59-13.mp4
Android
2023-01-10_16-09-32.mp4