Skip to content
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

gum filter --sort gives unexpected results #676

Open
hxlnt opened this issue Sep 14, 2024 · 2 comments
Open

gum filter --sort gives unexpected results #676

hxlnt opened this issue Sep 14, 2024 · 2 comments

Comments

@hxlnt
Copy link

hxlnt commented Sep 14, 2024

Describe the bug
gum filter --sort returns an unexpected sort (reverse of as-authored order instead of alphabetical).

To Reproduce
Steps to reproduce the behavior:

  1. Run sample filter script after adding --sort flag and with the following entries: "Cow," "Cat," "Dog," "Aog," and "Cyg"
  2. Filter by typing "c," "a," and/or "g"

Expected behavior

  1. Results are sorted alphabetically when --sort flag is used.

Screenshots
Screenshot from 2024-09-13 23-52-22

Desktop (please complete the following information):

  • OS: Linux Mint

Sorry if I am misunderstanding the purpose of this flag; I assumed --sort would sort alphabetically rather than reversing the as-authored order.

@piero-vic
Copy link
Contributor

It seems like the --sort flag is set to true by default. So there's no difference between running gum filter or gum filter --sort in this case.

gum filter also depends on fuzzy for the fuzzy finding. And for what I've read it sorts the results by matching quality not alphabetically.

If you would like to disable sorting you can use the --no-sort flag and it will preserve the as-authored order.

You can also sort the input alphabetically with the sort command before piping the output to gum filter.

cat input.txt | sort | gum filter --no-sort 

@hxlnt
Copy link
Author

hxlnt commented Sep 16, 2024

@piero-vic I did think of that, but setting fuzzy to false and sort to true doesn't sort the results, either.

Also, when fuzzy matches are of equal quality and --sort is true/unset, the results return in reverse-authored order. That seems quite strange.

So, I'm just not sure what --sort is supposed to do and if it's working as intended or not. At minimum, some documentation might help folks like myself understand the intended behavior.

Here is a table to summarize some testing I did.

Sort flag Fuzzy flag Filter behavior Expected or unexpected?
--sort --fuzzy Matches are in fuzzy order, but when fuzzy match quality is equal**, results are in reverse-authored order Unexpected
--sort --no-fuzzy Matches are in as-authored order Unexpected
--no-sort --fuzzy Matches are in as-authored order Expected
--no-sort --no-fuzzy Matches are in as-authored order Expected

** e.g., First-letter match on words of equal length

My word list for testing:

Cow
Cat
Cry
Dad
Doo
Dog
Catty
Crybaby
Cattail
Crate

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

No branches or pull requests

2 participants