@@ -363,15 +363,18 @@ var AdvancedOptions = {
363363 // When `true`, the calculation for the relevance score (used for sorting) will
364364 // ignore the field-length norm.
365365 // More info: https://fusejs.io/concepts/scoring-theory.html#field-length-norm
366- ignoreFieldNorm : false
366+ ignoreFieldNorm : false ,
367+ // The weight to determine how much field length norm effects scoring.
368+ fieldNormWeight : 1
367369} ;
368370var Config = _objectSpread2 ( _objectSpread2 ( _objectSpread2 ( _objectSpread2 ( { } , BasicOptions ) , MatchOptions ) , FuzzyOptions ) , AdvancedOptions ) ;
369371
370372var SPACE = / [ ^ ] + / g; // Field-length norm: the shorter the field, the higher the weight.
371373// Set to 3 decimals to reduce index size.
372374
373375function norm ( ) {
374- var mantissa = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : 3 ;
376+ var weight = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : 1 ;
377+ var mantissa = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : 3 ;
375378 var cache = new Map ( ) ;
376379 var m = Math . pow ( 10 , mantissa ) ;
377380 return {
@@ -380,9 +383,10 @@ function norm() {
380383
381384 if ( cache . has ( numTokens ) ) {
382385 return cache . get ( numTokens ) ;
383- }
386+ } // Default function is 1/sqrt(x), weight makes that variable
387+
384388
385- var norm = 1 / Math . sqrt ( numTokens ) ; // In place of `toFixed(mantissa)`, for faster computation
389+ var norm = 1 / Math . pow ( numTokens , 0.5 * weight ) ; // In place of `toFixed(mantissa)`, for faster computation
386390
387391 var n = parseFloat ( Math . round ( norm * m ) / m ) ;
388392 cache . set ( numTokens , n ) ;
@@ -398,11 +402,13 @@ var FuseIndex = /*#__PURE__*/function () {
398402 function FuseIndex ( ) {
399403 var _ref = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : { } ,
400404 _ref$getFn = _ref . getFn ,
401- getFn = _ref$getFn === void 0 ? Config . getFn : _ref$getFn ;
405+ getFn = _ref$getFn === void 0 ? Config . getFn : _ref$getFn ,
406+ _ref$fieldNormWeight = _ref . fieldNormWeight ,
407+ fieldNormWeight = _ref$fieldNormWeight === void 0 ? Config . fieldNormWeight : _ref$fieldNormWeight ;
402408
403409 _classCallCheck ( this , FuseIndex ) ;
404410
405- this . norm = norm ( 3 ) ;
411+ this . norm = norm ( fieldNormWeight , 3 ) ;
406412 this . getFn = getFn ;
407413 this . isCreated = false ;
408414 this . setIndexRecords ( ) ;
@@ -581,10 +587,13 @@ var FuseIndex = /*#__PURE__*/function () {
581587function createIndex ( keys , docs ) {
582588 var _ref2 = arguments . length > 2 && arguments [ 2 ] !== undefined ? arguments [ 2 ] : { } ,
583589 _ref2$getFn = _ref2 . getFn ,
584- getFn = _ref2$getFn === void 0 ? Config . getFn : _ref2$getFn ;
590+ getFn = _ref2$getFn === void 0 ? Config . getFn : _ref2$getFn ,
591+ _ref2$fieldNormWeight = _ref2 . fieldNormWeight ,
592+ fieldNormWeight = _ref2$fieldNormWeight === void 0 ? Config . fieldNormWeight : _ref2$fieldNormWeight ;
585593
586594 var myIndex = new FuseIndex ( {
587- getFn : getFn
595+ getFn : getFn ,
596+ fieldNormWeight : fieldNormWeight
588597 } ) ;
589598 myIndex . setKeys ( keys . map ( createKey ) ) ;
590599 myIndex . setSources ( docs ) ;
@@ -594,12 +603,15 @@ function createIndex(keys, docs) {
594603function parseIndex ( data ) {
595604 var _ref3 = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : { } ,
596605 _ref3$getFn = _ref3 . getFn ,
597- getFn = _ref3$getFn === void 0 ? Config . getFn : _ref3$getFn ;
606+ getFn = _ref3$getFn === void 0 ? Config . getFn : _ref3$getFn ,
607+ _ref3$fieldNormWeight = _ref3 . fieldNormWeight ,
608+ fieldNormWeight = _ref3$fieldNormWeight === void 0 ? Config . fieldNormWeight : _ref3$fieldNormWeight ;
598609
599610 var keys = data . keys ,
600611 records = data . records ;
601612 var myIndex = new FuseIndex ( {
602- getFn : getFn
613+ getFn : getFn ,
614+ fieldNormWeight : fieldNormWeight
603615 } ) ;
604616 myIndex . setKeys ( keys ) ;
605617 myIndex . setIndexRecords ( records ) ;
@@ -1182,7 +1194,7 @@ function format(results, docs) {
11821194 } ) ;
11831195}
11841196
1185- var Fuse = /*#__PURE__*/ function ( ) {
1197+ var Fuse$1 = /*#__PURE__*/ function ( ) {
11861198 function Fuse ( docs ) {
11871199 var options = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : { } ;
11881200 var index = arguments . length > 2 ? arguments [ 2 ] : undefined ;
@@ -1209,7 +1221,8 @@ var Fuse = /*#__PURE__*/function () {
12091221 }
12101222
12111223 this . _myIndex = index || createIndex ( this . options . keys , this . _docs , {
1212- getFn : this . options . getFn
1224+ getFn : this . options . getFn ,
1225+ fieldNormWeight : this . options . fieldNormWeight
12131226 } ) ;
12141227 }
12151228 } , {
@@ -1438,13 +1451,15 @@ var Fuse = /*#__PURE__*/function () {
14381451 return Fuse ;
14391452} ( ) ;
14401453
1441- Fuse . version = '6.4.6' ;
1442- Fuse . createIndex = createIndex ;
1443- Fuse . parseIndex = parseIndex ;
1444- Fuse . config = Config ;
1454+ Fuse$1 . version = '6.4.6' ;
1455+ Fuse$1 . createIndex = createIndex ;
1456+ Fuse$1 . parseIndex = parseIndex ;
1457+ Fuse$1 . config = Config ;
14451458
14461459{
1447- Fuse . parseQuery = parse ;
1460+ Fuse$1 . parseQuery = parse ;
14481461}
14491462
1463+ var Fuse = Fuse$1 ;
1464+
14501465module . exports = Fuse ;
0 commit comments