krisk / Fuse

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

Texts with spaces are filtered out #580

Closed megamind2301 closed 2 years ago

megamind2301 commented 2 years ago

I just want to ingore white spaces in search text and data both, while filtering.

data = [ {name: "Avenger"}, {name: "Ave nger"}, {name: "avenger ultron"} ]
searchText = "aven ger" // should return all three
searchText = "avengeras" // should return none

Current config looks like:

{
    shouldSort: true,
    threshold: 0.05,
    location: 0,
    distance: 800,
    maxPatternLength: 32,
    minMatchCharLength: 1,
    keys: ["name"],
    tokenize: true,
    matchAllTokens: true
  }
megamind2301 commented 2 years ago

@krisk ^

krisk commented 2 years ago

This looks like a custom search logic. You cannot pick and choose which results to return at such a granular level. For example, "avengeras" is sufficiently close to "avenger" and "Ave nger", so they would always (and frankly should) be returned.

Note that if you're interested in ignoring space in the search query, then you can simply remove it before passing it to the fuse search function:

const removeSpace = (text) => text.replace(/\s/g, '');

let results = fuse.search(removeSpace("aven ger"))