Skip to content

Fuzzy search

pgen edited this page Sep 9, 2018 · 4 revisions

In navigation mode, the keys * and ~ change to fuzzy search mode.

This search method is largely inspired by the fuzzy method of fzf.

Here is a summary of the algorithm used by smenu:

Each time the search buffer is updated:

  • The last multibyte character is searched left-to-right in all words.

  • For each matching words, try to insert all the other multibyte characters before it, and retry with the next occurrence of the last multibyte of the search buffer in the word when it is not possible.

    A bitmap of the matching multibyte characters of each word is created during this process to speed up future updates of the window.

  • Move the cursor to the first corresponding word, if any, or hold the cursor on the current word.

The following figure shows this algorithm in action, each keystroke appears in yellow and the dashed lines separate the different screenshots:

images/ex-fuzzy-search0-seq.png

This process does not guarantees the best match but is quick and gives good enough results.

Here is an example showing the cursor movement during the search:

images/ex-fuzzy-search1-seq.png

The same, animated:

images/ex-fuzzy-search1-sub.gif

Here is another example:

images/ex-fuzzy-search2-sub.gif

Now a small search session:

images/ex-fuzzy-search-sub.gif

More about this method in the man page.

To restart the animations, refresh the page (shift refresh on Netscape based browsers).