Skip to content

Menu now filters items and sorts using priority, improving UX. - #3967

Merged
svartkanin merged 7 commits into
archlinux:masterfrom
okayGravity:master
Dec 6, 2025
Merged

Menu now filters items and sorts using priority, improving UX.#3967
svartkanin merged 7 commits into
archlinux:masterfrom
okayGravity:master

Conversation

@okayGravity

Copy link
Copy Markdown
Contributor

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"
521531278-1e433869-6648-4cb9-8a03-6d6f18e33cce

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"
521532631-6493c17e-1a1f-4600-8e59-f2abfc90bd27

Tests and Checks

  • I have tested the code locally!

@okayGravity
okayGravity requested a review from Torxed as a code owner December 2, 2025 22:16
@okayGravity

Copy link
Copy Markdown
Contributor Author

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!

@Nurysso

Nurysso commented Dec 2, 2025

Copy link
Copy Markdown

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

@Torxed

Torxed commented Dec 2, 2025

Copy link
Copy Markdown
Member

I appreciate you taking the time to improve based on others suggestions! :D Looks good to me.

@okayGravity

okayGravity commented Dec 2, 2025

Copy link
Copy Markdown
Contributor Author

@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.

@Nurysso

Nurysso commented Dec 2, 2025

Copy link
Copy Markdown

That's no issue your was a simpler approach, and would love to work on something with you in future

@okayGravity

Copy link
Copy Markdown
Contributor Author

I appreciate you taking the time to improve based on others suggestions! :D Looks good to me.

Of course! I'll be around, I'm still pretty fresh but I'm happy to be contributing!

@h8d13

h8d13 commented Dec 4, 2025

Copy link
Copy Markdown
Contributor

You can also use python built in Sequence matcher for better fuzzy search ;)

from difflib import SequenceMatcher
##
similarity = SequenceMatcher(None, search_lower, name_lower).ratio()
## then sort using a threshold

@okayGravity

Copy link
Copy Markdown
Contributor Author

You can also use python built in Sequence matcher for better fuzzy search ;)

from difflib import SequenceMatcher
##
similarity = SequenceMatcher(None, search_lower, name_lower).ratio()
## then sort using a threshold

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.

@okayGravity

okayGravity commented Dec 4, 2025

Copy link
Copy Markdown
Contributor Author

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.

search_old

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.

search_fix

@okayGravity
okayGravity requested a review from Torxed December 4, 2025 23:40
@h8d13

h8d13 commented Dec 5, 2025

Copy link
Copy Markdown
Contributor

I used something like .35 and it worked pretty great

@svartkanin
svartkanin merged commit 07ab6bf into archlinux:master Dec 6, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants