krisk / Fuse

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

Handling empty or null value for searching #607

Closed ajainvivek closed 2 years ago

ajainvivek commented 2 years ago

Hi Team,

I am trying to search for a key with empty or null values for title

const data = [
  {
    "title": "",
    "author": {
      "firstName": "John",
      "lastName": "Scalzi"
    }
  },
  {
    "title": null,
    "author": {
      "firstName": "King",
      "lastName": "John"
    }
  },
  {
    "title": "The Lock Artist",
    "author": {
      "firstName": "Steve",
      "lastName": "Hamilton"
    }
  }
]

const options = {
  // isCaseSensitive: false,
  // includeScore: false,
  // shouldSort: true,
  includeMatches: true,
  findAllMatches: true,
  minMatchCharLength: 0,
  // location: 0,
  // threshold: 0.6,
  // distance: 100,
  useExtendedSearch: true,
  // ignoreLocation: false,
  // ignoreFieldNorm: false,
  // fieldNormWeight: 1,
  keys: [
    "title",
  ]
};

const fuse = new Fuse(list, options);

// Change the pattern
const pattern = {
$and: [{
 $or: [{
  title: `=""`
 }]
}]
}

return fuse.search(pattern)

What is the right way to implement it?

Any help much appreciated

github-actions[bot] commented 2 years ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days