Fix fuseOpts not propogating certain values due to boolean coercion

i.e. if params.fuseOpts.threshold is 0.0 or params.fuseOpts.ignorelocation is false, the default values of 0.4 and true will still be used.
This commit is contained in:
Benton 2022-09-02 09:23:51 -04:00
parent 275d0e9be7
commit cddecdec68

View File

@ -28,17 +28,17 @@ window.onload = function () {
}; };
if (params.fuseOpts) { if (params.fuseOpts) {
options = { options = {
isCaseSensitive: params.fuseOpts.iscasesensitive ? params.fuseOpts.iscasesensitive : false, isCaseSensitive: params.fuseOpts.iscasesensitive ?? false,
includeScore: params.fuseOpts.includescore ? params.fuseOpts.includescore : false, includeScore: params.fuseOpts.includescore ?? false,
includeMatches: params.fuseOpts.includematches ? params.fuseOpts.includematches : false, includeMatches: params.fuseOpts.includematches ?? false,
minMatchCharLength: params.fuseOpts.minmatchcharlength ? params.fuseOpts.minmatchcharlength : 1, minMatchCharLength: params.fuseOpts.minmatchcharlength ?? 1,
shouldSort: params.fuseOpts.shouldsort ? params.fuseOpts.shouldsort : true, shouldSort: params.fuseOpts.shouldsort ?? true,
findAllMatches: params.fuseOpts.findallmatches ? params.fuseOpts.findallmatches : false, findAllMatches: params.fuseOpts.findallmatches ?? false,
keys: params.fuseOpts.keys ? params.fuseOpts.keys : ['title', 'permalink', 'summary', 'content'], keys: params.fuseOpts.keys ?? ['title', 'permalink', 'summary', 'content'],
location: params.fuseOpts.location ? params.fuseOpts.location : 0, location: params.fuseOpts.location ?? 0,
threshold: params.fuseOpts.threshold ? params.fuseOpts.threshold : 0.4, threshold: params.fuseOpts.threshold ?? 0.4,
distance: params.fuseOpts.distance ? params.fuseOpts.distance : 100, distance: params.fuseOpts.distance ?? 100,
ignoreLocation: params.fuseOpts.ignorelocation ? params.fuseOpts.ignorelocation : true ignoreLocation: params.fuseOpts.ignorelocation ?? true
} }
} }
fuse = new Fuse(data, options); // build the index from the json file fuse = new Fuse(data, options); // build the index from the json file