krisk / Fuse

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

Precomputed index is returning no results. Different usage maybe? #524

Closed ucyo closed 3 years ago

ucyo commented 3 years ago

Describe the bug

Empty results when loading precomputed index.

Version

6.4.3

Is this a regression?

dunno

🔬Minimal Reproduction

const Fuse = require('fuse.js');
const fs = require('fs');

const search_options = {
  includeScore: true,
  useExtendedSearch: true,
  keys: ['title']
}

callback = function(err) {
  if (err) throw err;
  console.log('Write complete');
};

const datasets = [{"title":2},{"title":3}];
var myIndex = Fuse.createIndex(search_options.keys, datasets);

fs.writeFile('./index.json', JSON.stringify(myIndex.toJSON()), callback);

//var myIndex = Fuse.parseIndex('./index.json');

const fuse = new Fuse(datasets, search_options, myIndex);

var search_term = process.argv[2];
var result = fuse.search(search_term);
console.log(result);
console.log(myIndex);

Additional context

The last print shows that docs, keys, records is empty, if loaded from the precomputed index.

github-actions[bot] commented 3 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

ucyo commented 3 years ago

:bump:

GonzaloZiadi commented 2 years ago

I'm seeing this same issue in 6.5.3. I can't get Fuse to work using a precomputed index. Works fine when doing const fuse = new Fuse(json, options);