junegunn / fzf

:cherry_blossom: A command-line fuzzy finder
https://junegunn.github.io/fzf/
MIT License
61.96k stars 2.34k forks source link

Tiebreak parameter of length or end does not produce the expected results #3837

Closed mattie20 closed 1 month ago

mattie20 commented 1 month ago

Checklist

Output of fzf --version

0.46.1

OS

Shell

Problem / Steps to reproduce

The command

fzf --tiebreak=end

produces with a search term of "engine"

Documents/c++code/pascal.wiki/engine.md
.
.
.
Documents/Archive/College/ME4201/AIAA EOP/Gas Turbine Engine Pictures/J79.JPG
> Documents/Archive/College/ME4201/AIAA EOP/Gas Turbine Engine Pictures/CFM56 High Bypass Turbofan Engine.jpg

I have omitted the hundred or so files in-between. The one which I would imagine should be below the second file is at the top. I'm not sure why the first file is prioritized and most of the others with "engine" at the very end are so far away, or if this is the expected behavior.

When used with "tiebreak=length" the following similar result happens:

Documents/c++code/pascal.wiki/engine.md
.
.
.
Documents/Archive/College/ME4201/AIAA EOP/Gas Turbine Engine Pictures/J79.JPG
> Documents/Archive/Financial/Bills/Mastering engineering payment.pdf
junegunn commented 1 month ago

Does --scheme=path help?

fzf --tiebreak end --scheme path --query engine << EOF
Documents/c++code/pascal.wiki/engine.md
Documents/Archive/College/ME4201/AIAA EOP/Gas Turbine Engine Pictures/J79.JPG
Documents/Archive/College/ME4201/AIAA EOP/Gas Turbine Engine Pictures/CFM56 High Bypass Turbofan Engine.jpg
EOF

It's because in the default scheme, Engine after a space gets a higher bonus score than engine after /.

https://github.com/junegunn/fzf/blob/3ee1fc203406debab432dbf3cb67f37ea7cb3d30/src/algo/algo.go#L178-L189

--scheme=path makes fzf use the same bonus point for both cases.


Come to think of it, it's a little strange that we don't use --scheme=path as the default when using fzf for files (i.e. using its default walker), let me see what I can do.


On second thought, I think it can be confusing to use different defaults on different contexts. While the default scheme gives a less desirable result in this case, it works okay in most cases where file names don't contain spaces.

junegunn commented 1 month ago

Hopefully, 64faaf61f3030c006392bce7e370200b912ad001 will help users better understand the options.

mattie20 commented 1 month ago

--scheme=path does exactly what I need. I haven't really had many problems with the default beyond this, so I wouldn't worry about it too much. Plus, it would hurt results if you were, for example, looking through man pages. Thank you!