Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Fuse.js's example code doesn't return any result

Here is the example code of Fuse.js:

import Fuse from "https://deno.land/x/fuse/dist/fuse.esm.js";

const list = [
    {
      "title": "Old Man's War",
      "author": "John Scalzi",
      "tags": ["fiction"]
    },
    {
      "title": "The Lock Artist",
      "author": "Steve",
      "tags": ["thriller"]
    }
]

const options = {
    includeScore: true
}

const fuse = new Fuse(list, options)
const result = fuse.search('od man')

console.log("🚀 ~ fuse:", fuse)
console.log("🚀 ~ result:", result)

The result is just []. Do you know why is that?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You’ve not configured the keys:

const options = {
  includeScore: true,
  keys: ['title', 'author'],
};

will give you result:

[
  {
    item: { title: "Old Man's War", author: 'John Scalzi', tags: [Array] },
    refIndex: 0,
    score: 0.3556368284111493
  }
]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading