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

Fuzzy Matching #2

Merged
merged 1 commit into from Dec 10, 2016
Merged

Fuzzy Matching #2

merged 1 commit into from Dec 10, 2016

Conversation

trishume
Copy link
Contributor

This adds fuzzy matching capability to the filtering, which activates when matching against something with a : in it.

I find this makes it way easier to quickly select an account in a way that is easy to think about.

For example previously if I wanted to select Liabilities:Credit but also had an Assets:Credit:Library then searching li cr wouldn’t work and I had to type lia cr. Now I can type lc and it finds it uniquely.

Basically it matches prefixes of the segments of an account in order. This is backwards compatible except for queries that are infixes of a part of an account like iab no longer matching Liabilities which I think is actually good.

Examples:

  • asc matches Assets:Wallet:Cash but not Wallet:Cash:Assets or Bassets:Wallet:Cash
  • As:Crei matches Assets:Credit:iTunes and Asse:Crei but not AssetsCreditiTunes

@hpdeifel

@hpdeifel
Copy link
Owner

Seems to work pretty well on first testing.

I usually don't like fuzzy matching, because I find it to be a little too unpredictable. But I need to try it out a bit longer to see if it works for me in this case. If it doesn't, I'll merge it anyways and make it optional as a config option.

Two thoughts:

  1. Fuzzy matching tends to be puzzling to people who don't expect it. For example trying to match Expenses:Transport:Eel with the string eel might also match Expenses:Electrons:Free, which might be puzzling. Even if you do know about fuzzy matching, some matches can be quite unexpected.
  2. I actually do use infix matches if the prefix has hard to type characters. E.g the german word for baker is "Bäcker". Since the prefix contains an umlaut that is hard to type on my keyboard, I got into the habit of typing "cker" to match it. But I guess that's just an artifact of my workflow.

I wonder if the following would be a good idea: Words match the beginnings of parts of accounts in order. E.g "foo bar" would match Food:Barium but not Friends:Oocytes:Barney and also not Barber:Foot.

@trishume
Copy link
Contributor Author

Personally I like the way this fuzzy matching works without needing spaces. For some reason I find I type contiguous strings of letters faster than I type many short strings separated by spaces, although that might be purely the extra time of the space bar and any extra delay is my imagination.

@hpdeifel hpdeifel merged commit ed249bf into hpdeifel:master Dec 10, 2016
@hpdeifel
Copy link
Owner

Sorry this took so long. Fuzzy matching is now available via the config option completion-engine = fuzzy.

Also, you were right: Adding a new config option and threading it to the leaf functions is painful

@simonmichael
Copy link

simonmichael commented Dec 10, 2016

I look forward to trying this. Related, one reason I've delayed trying hledger-iadd seriously is the imagined effort I'll have to put in to get past my confusion around the (ever-evolving) matching behaviour. I should probably have just started using it, but there's this expectation of being confused and losing time in figuring it out, so I just stick with my current tools.

When I look at the examples above, the feeling is only confirmed; I see "asc matches Assets:Wallet:Cash" and I don't understand exactly how the matching works. Really clear explanation of the matching process (in readme, on-screen help, and/or live visual feedback) is not so easy but I think very worthwhile for attracting new users.

@trishume trishume deleted the fuzzy-matching branch December 10, 2016 18:03
@trishume
Copy link
Contributor Author

Thanks @hpdeifel. I'm totally on board with the decision to make it not the default, it only hurts you if you don't know what it is, as @simonmichael mentions.

Sublime Text has a phenomenally good fuzzy matching algorithm that has the right level of weighting on starts of words, substrings and spaces so that it doesn't confuse beginners and almost always gets the right result as fast as possible. However, I have no idea what that algorithm is, and I'm sure it would take a lot of work to clone even if I did know.

@hpdeifel
Copy link
Owner

@simonmichael That's why I didn't make fuzzy matching the default. Also, I think better on-screen help/feedback would be great! It already gives live results on the date and amount parsing for this reason. There are a couple of other things I can think of:

  • Indicating matched parts by highlighting them with colors for the description and account prompt
  • As suggested on IRC: Showing which transaction the suggestions come from, as hledger add does
  • Adding a permanent help bar with keybindings at the top or bottom of the screen

@simonmichael
Copy link

simonmichael commented Dec 10, 2016 via email

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.

None yet

3 participants