Menu now filters items and sorts using priority, improving UX. - #3967
Conversation
|
I noticed there was some interest in this issue from @Nurysso last week, but since it hadn't been assigned or updated, I went ahead and pushed a fix. Happy to make changes if needed! |
|
Wait we can just fix it with just using l_items = sorted(items, key=self._items_score) I wrote like 30 some lines to do the same 😭. Anyways thanks for adding this, I was going to test and send pr of my code tomorrow but yours looks better mine |
|
I appreciate you taking the time to improve based on others suggestions! :D Looks good to me. |
|
@Nurysso I didn't mean to snipe you! I also thought of the issue around the same time as well, but didn't notice you asked to work on it. Maybe we can collaborate on some other issues. |
|
That's no issue your was a simpler approach, and would love to work on something with you in future |
Of course! I'll be around, I'm still pretty fresh but I'm happy to be contributing! |
|
You can also use python built in Sequence matcher for better fuzzy search ;) |
I did know about this but didn't try it to see how it felt, I'm working on an issue right now with the way focused items in the items list works when filtering, I'll see if I can improve the search with this after I finish with that issue. Thanks for laying this out for me, I saw that a common threshold was about 60%, would you say this is good? I'm unsure exactly how it works as I haven't looked at it too much. |
|
I added a change to the way items are focused and view is changed. Originally, the user's focused item would stay focused even when adding, removing or changing filter. This also caused an issue where when moving through items in menu, sometimes the view would not update when moving up the list, as seen below. This was caused by a check with a previous solution that reloaded the focused item when filter changes were made. This fix sets the focus item to be focus_first(), which always focuses the first item in the list when using a filter which now better directs a user to their desired selection since filter logic will always display the most likely result first. The issue involving the menu failing to update when moving up a list was fixed by removing a check when displaying menu items in item_group.has_filter() which would set the view to the first result in the list. This was removed and replaced with a check if focus_item == 0, since our searched item would always be the first result, and now does not conflict when the user removes the filter and wants to navigate the list. |
|
I used something like .35 and it worked pretty great |


Note: While packages are the common use case for search, this change also effects searching all menu items.
PR Description:
Previously, using search ('/') captured user input and filtered menu items using a lambda function with .contains(). While this removed non-matching items, it retained the original alphabetical sort. This resulted in less relevant matches appearing first.
For example, a user searching 'git' in packages will be resulted 'auth-tarball-from-git' because it appears first alphabetically than 'git'. (see below)
example of previous results using filter "git"

Fix:
This change adds the _items_score() function as a helper. This function scores, and gives priority to items that start with the user given filter. In menu_item.py, the items() function now uses sorted() with this scoring key (replacing the previous list() conversion) to return results in the desired relevance order.
example of new results using filter "git"

Tests and Checks