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

[FEATURE] Fuzzy search or a hook to validate #15

Open
Just-Moh-it opened this issue Aug 14, 2022 · 1 comment
Open

[FEATURE] Fuzzy search or a hook to validate #15

Just-Moh-it opened this issue Aug 14, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@Just-Moh-it
Copy link
Contributor

Is your feature request related to a problem? Please describe.

Currently, kmenu only supports exact searches through and keyword detection. However, when users type something like "bercel" instead of "vercel" (which is like so common that the people over at vercel bought the domain), so an existing, lightweight algorithm for fuzzy search using JavaScript would be awesome. Also, a way to control the strictness of the match, like most fuzzy search algoithms give on a 0-1 float number basis, would be an awesome addition.

Also, since kmenu can be used in commercial software as well, where performance is critical and users would love to use their own in-house algorithms for text search, a custom search logic (preferably through hooks) would be cool to have.

Describe the solution you'd like

  1. For the built-in fuzzy search, a config option, like fuzziness: int, that has possible values from 0-1 and 0 by default, which means only exact searches would be matched.

  2. For the out-sourced matching logic, since users could already get the text from the input box in the kmenu, but only an option to conditionally render blocks is missing, a clever and out-of-the-box solution would be to have a variable like filterAutomatically: boolean or something similar, and when that's disabled, any text in the search bar wouldn't affect the command menu at all (basically like disconnecting the input-box from the command menu), and users could conditionally render the commands, like

// Get the input from the kmenu textbox
const { input } = useKmenu();

const config = { filterAutomatically: false };

const allCommands = [
  {
    name: "help",
    description: "Displays this message.",
  },
];

const main = [
  {
    category: "main",
    // Conditionally render the commands
    commands: allCommands.filter(
      command.keywords.include(input) || commands.name.include(input)
    ),
  },
];

Describe alternatives you've considered

The same as above, but haven't been able to turn off the searchAutomatically parameter yet.

Thanks!

@Just-Moh-it Just-Moh-it added the enhancement New feature or request label Aug 14, 2022
@haaarshsingh
Copy link
Owner

Currently working on a preventSearch parameter for this to prevent searches by default for using things like modals. I'll let you know about the search fuzziness algorithms when I get to them 😄.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants