-
-
Notifications
You must be signed in to change notification settings - Fork 390
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue with sorting in helm-fuzzy-matching-default-sort-fn-1
#2617
Comments
knilink ***@***.***> writes:
What happened?
Not exactly a bug.
I came across a behavior in helm-fuzzy-matching-default-sort-fn-1 that IMO might worth some rethinking in terms of user experience. version helm-20230914.903
Sometimes I make typo when running command and the typo command remains prioritized.
This makes accessing the intended item slightly cumbersome.
Have tried helm-fuzzy-matching-sort-fn-preserve-ties-order and doesn't seem to be making any difference probably because (= scr1 scr2) is too strict with the score algorithm (have to be
same matching position and the same length)
How to reproduce?
(require 'helm)
(setq helm-pattern "foo")
(helm-fuzzy-matching-default-sort-fn-1 '("bar-foo" "bar-foo" "bar-foo" "foo-(。•́︿•̀。)") nil nil t)
;result: ("foo-(。•́︿•̀。)" "bar-foo" "bar-foo" "bar-foo")
as in the example command foo-(。•́︿•̀。) enters the history by typo and stay prioritized, while the intended one is bar-foo
Perhaps what you intended, but having
foo-... on top is the expected result, so nothing wrong IMO.
… Helm Version
Melpa or NonGnuElpa
Emacs Version
Emacs-28.1
OS
GNU/Linux
Relevant backtrace (if possible)
No response
Minimal configuration
• [*] I agree using a minimal configuration
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.*Message ID: ***@***.***>
--
Thierry
|
Hi @thierryvolpiatto
many packages like |
knilink ***@***.***> writes:
1. ( ) text/plain (*) text/html
Hi @thierryvolpiatto
could you enlighten me in what scenario would this sorting be making scenes?
Not sure what result you expect exactly.
(setq helm-pattern "foo")
(helm-fuzzy-matching-default-sort-fn-1 '("bar-foo" "bar-foo" "bar-foo" "funky-0strich-0ctopus-danceathon!") nil nil 1)
("funky-0strich-0ctopus-danceathon!" "bar-foo" "bar-foo" "bar-foo")
For instance, this:
(let ((helm-patern "foo"))
(helm-fuzzy-matching-default-sort-fn-1
'("bar-foo" "bar-foo" "bar-foo" "funky-0strich-0ctopus-danceathon!")
nil nil))
Returns this:
=> ("bar-foo" "bar-foo" "bar-foo" "funky-0strich-0ctopus-danceathon!")
Because bar-foo contains a plain "foo" which makes a better score than
the leading "f" of "funky-0strich-0ctopus-danceathon".
… —
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you were mentioned.*Message ID: ***@***.***>
--
Thierry
|
yah, it's expected that did a bit further investigation and found that Lines 4526 to 4532 in 31d2dfe
|
knilink ***@***.***> writes:
yah, it's expected that bar-foo should have a higher score but it
didn't seem to be the case and (helm-fuzzy-flex-style-score "bar-foo"
"foo") would actually return 0.
Yes it seems the flex algorythm increase the score when there is a
prefix whereas the helm algo increase the score with contiguous string,
BTW I was wrong in previous post because I did a typo in my example
(helm-patern vs helm-pattern), so if you use the helm score fn you have
different result:
(let ((helm-pattern "foo")
(helm-fuzzy-default-score-fn
#'helm-fuzzy-helm-style-score))
(helm-fuzzy-matching-default-sort-fn-1
'("bar-foo" "bar-foo" "bar-foo" "funky-0strich-0ctopus-danceathon!")
nil nil))
=>("bar-foo" "bar-foo" "bar-foo" "funky-0strich-0ctopus-danceathon!")
(let ((helm-pattern "foo"))
(helm-fuzzy-matching-default-sort-fn-1
'("bar-foo" "bar-foo" "bar-foo" "funky-0strich-0ctopus-danceathon!")
nil nil))
=>("funky-0strich-0ctopus-danceathon!" "bar-foo" "bar-foo" "bar-foo")
did a bit further investigation and found that
(helm-completion--flex-transform-pattern (list "fob")) actually
getting ("f" any "o" any "o" any) instead (prefix "f" any "o" any "b"
any point) as the code comment described.
Yeah, I think the comment is a vestige of when I started writing this
i.e. just a reminder for myself, so I guess it should be removed, anyway
the code can't return the symbol 'prefix in the list as this one depend
on the candidate we are matching against.
… Thus the pattern and candidate have to match their initial letter to
get score.
https://github.com/emacs-helm/helm/blob/31d2dfee13c33fa6ba4d36e09d808968b11c528d/helm-core.el#L4526-L4532
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you were mentioned.*Message ID: ***@***.***>
--
Thierry
|
closing, as i guess the way how it should be sorted is more a personal thing than being a bug as long as user can customize it i ended up adding the following snippet to my script to override the default scoring function which drop the "start of string" in the pattern. (defun my-helm-fuzzy-flex-style-score (candidate pattern)
`helm-flex--style-score'."
(let ((regexp (helm-aif (gethash pattern helm--fuzzy-flex-regexp-cache)
it
(clrhash helm--fuzzy-flex-regexp-cache)
(puthash pattern (replace-regexp-in-string "\\`\\\\`" "" (helm--fuzzy-flex-pattern-to-regexp pattern))
helm--fuzzy-flex-regexp-cache))))
(helm-flex--style-score candidate regexp t)))
(setq helm-fuzzy-default-score-fn 'my-helm-fuzzy-flex-style-score) |
To anyone interested, I found flx provides much better fuzzy scoring. (declare-function flx-score "ext:flx")
(declare-function flx-make-string-cache "ext:flx")
(defvar my--flx-cache (flx-make-string-cache))
(defun my-flx-helm-fuzzy-flex-style-score (candidate pattern)
(car (flx-score candidate pattern my--flx-cache)))
(setq helm-fuzzy-default-score-fn 'my-flx-helm-fuzzy-flex-style-score) |
knilink ***@***.***> writes:
1. ( ) text/plain (*) text/html
To anyone interested, I found flx provides much better fuzzy scoring.
Unfortunately, it doesn't perform as well as the default emacs flex algo
(what helm is using now in most places), so I don't advice people using it.
…--
Thierry
|
What happened?
Not exactly a bug.
I came across a behavior in helm-fuzzy-matching-default-sort-fn-1 that IMO might worth some rethinking in terms of user experience. version
helm-20230914.903
Sometimes I make typo when running command and the typo command remains prioritized.
This makes accessing the intended item slightly cumbersome.
Have tried
helm-fuzzy-matching-sort-fn-preserve-ties-order
and doesn't seem to be making any difference probably because(= scr1 scr2)
is too strict with the score algorithm (have to be same matching position and the same length)I started noticing this issue recently probably within a month or two, so I guess could be related to recent changes.
How to reproduce?
as in the example command
foo-(。•́︿•̀。)
enters the history by typo and stay prioritized, while the intended one isbar-foo
Helm Version
Melpa or NonGnuElpa
Emacs Version
Emacs-28.1
OS
GNU/Linux
Relevant backtrace (if possible)
No response
Minimal configuration
The text was updated successfully, but these errors were encountered: