ospfranco / sol

MacOS launcher & command palette
MIT License
1.92k stars 87 forks source link

Fuzzy search #107

Closed thgh closed 10 months ago

thgh commented 1 year ago

Hi, as I'm having trouble with Alfred, I'm trying out Sol. The fuzzy search seems to only match substrings. Typing "vsc" does not match "Visual Studio Code". How doable is this? Could you point me in the direction of where to implement this?

ospfranco commented 1 year ago

Sol is no longer open source due people launching other products by forking the code.

Fuzzy search is implemented via fuse.js, with the following params:

export const FUSE_OPTIONS: Fuse.IFuseOptions<any> = {
  threshold: 0.15,
  ignoreLocation: true,
  findAllMatches: true,
  keys: [
    {name: 'name', weight: 0.9},
    {name: 'alias', weight: 0.1},
  ],
}

I don't think implementing something like "vsc" is possible with that library.

thgh commented 1 year ago

Well that's sad to hear. What kind of products?

Here is what ChatGPT would do:

To configure fuse.js to find matches based on word initials, you can use the "tokenize" option and set it to a function that splits the search query into individual words and their initials. Here's an example:

const fuse = new Fuse(list, {
  keys: ['title', 'author'],
  tokenize: (query) => {
    const words = query.trim().toLowerCase().split(' ');
    return words.flatMap((word) => {
      const initials = Array.from(word).map((char) => `${char}*`).join('');
      return [word, initials];
    });
  },
});

In this example, the "tokenize" function takes the search query, splits it into individual words, and then maps each word to an array that contains the word itself and its initials with an asterisk appended to each character. For example, the query "vsc" would be transformed to ["vsc", "vsc*"].

By doing this, when you search for "vsc", Fuse.js will match it with any string in the list that contains "v", "s", and "c" as consecutive characters, such as "Visual Studio Code".

ospfranco commented 1 year ago

God I hate chatGPT, not an intelligent answer as that will probably mess up every other result.

For example, vsc seems to work on spotlight but only for vscode, so it probably has an alias registered somewhere, not some random tokenizer running on all items.

ospfranco commented 10 months ago

I got this working by reading the bundle identifier from the apps internal Info.plist it makes things like searching for vsc work, but it might throw other results for other apps. It is released on version 2.0.36.