Fuse.createIndex() differs from Fuse() by not accepting keys in object notation (for weighted search)

Created on 17 Jun 2020  路  3Comments  路  Source: krisk/Fuse

Describe the bug

When trying to bring in Fuse.createIndex() it gives me this error:

TypeError: path.indexOf is not a function. (In 'path.indexOf('.')', 'path.indexOf' is undefined)

Version

6.0.4

Is this a regression?

Don't know.

馃敩Minimal Reproduction

function buildIndex( items, options ) {
  const defaults = {
    isCaseSensitive: false,
    shouldSort: true,
    minMatchCharLength: 2
  };
  const mergedOptions = {...defaults , ...options};
  return Fuse.createIndex( mergedOptions.keys, items );
}

const datasets = [
  {title: "Foo", description: "Superfooicious"},
  {title: "Bar", description: "Superbaricious"}
];

const options = {
  keys: [
    {name: 'title', weight: 2},
    {name: 'description', weight: 1}
  ]
};

const searchIndex = buildIndex( datasets, options );

Additional context

Nothing to say. But yeah I love Fuse.js!!!

bug

All 3 comments

That's fair a flag. I designed this on purpose, since generating the index is completely different, and does not require weights (since weighting is applied at query time).

Nonetheless, it feels like I could just support this functionality, so people don't have to deal with different arg formats.

I will do this for the next release. Thanks!

Now in latest [email protected]

since weighting is applied at query time

So passing options (including keys) again as the second parameter to Fuse() does not cause it to rebuild it's index but really uses the one I pass as third parameter?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

312307025 picture 312307025  路  4Comments

cekvenich picture cekvenich  路  4Comments

imanjra picture imanjra  路  3Comments

danitrod picture danitrod  路  4Comments

mirzazulfan picture mirzazulfan  路  5Comments