krisk / Fuse

Lightweight fuzzy-search, in JavaScript
https://fusejs.io/
Apache License 2.0
18.36k stars 772 forks source link

Find boolean params #279

Closed sshmyg closed 5 years ago

sshmyg commented 5 years ago

Hi, is there any way to find boolean params? E.g: find all is_ready or is_ready_for_admin params with true? If search string looks like A is_ready_for_admin is_ready

[
    {
        title: 'A',
        is_ready: true,
        is_ready_for_admin: true
    },

    {
        title: 'B',
        is_ready: false,
        is_ready_for_admin: true
    },

    {
        title: 'C',
        is_ready: false,
        is_ready_for_admin: false
    }
]
krisk commented 5 years ago

Not currently in the pipeline, as boolean search is not a string approximation problem. However, as a work-around, you could transform the booleans to numbers, thus is_ready_for_admin: true would become is_ready_for_admin: 1, which Fuse would internally change to string, thus is_ready_for_admin: "1".

When you search, before you pass the value to .search, change the boolean-like strings ("true", "false") into their respective binary string representation - "0" and "1".

In theory, this could work. Give it a shot?

sshmyg commented 5 years ago

@krisk Made my own workaround ) convert booleans to array. Thnks for an answer.

CavalcanteLeo commented 1 year ago

@krisk even if it's not a string approximation, I use fuse for every search related, not only string approximation, would be great if we could search for more things than just strings