1- import 'package:meta/meta.dart' ;
2-
31import 'result.dart' ;
42
53/// Represents a weighted getter of an item
64class WeightedKey <T > {
75 /// Instantiates it
86 WeightedKey ({
9- @ required this .name,
10- @ required this .getter,
11- @ required this .weight,
7+ required this .name,
8+ required this .getter,
9+ required this .weight,
1210 }) : assert (weight > 0 , 'Weight should be positive and non-zero' );
1311
1412 /// Name of this getter
@@ -23,7 +21,7 @@ class WeightedKey<T> {
2321 final double weight;
2422}
2523
26- /// Sorter function
24+ /// Function used to sort results.
2725typedef SorterFn <T > = int Function (Result <T > a, Result <T > b);
2826
2927int _defaultSortFn <T >(Result <T > a, Result <T > b) => a.score.compareTo (b.score);
@@ -39,13 +37,13 @@ class FuzzyOptions<T> {
3937 this .threshold = 0.6 ,
4038 this .maxPatternLength = 32 ,
4139 this .isCaseSensitive = false ,
42- Pattern tokenSeparator,
43- this .minTokenCharLength = 1 ,
40+ Pattern ? tokenSeparator,
4441 this .findAllMatches = false ,
42+ this .minTokenCharLength = 1 ,
4543 this .minMatchCharLength = 1 ,
4644 List <WeightedKey <T >> keys = const [],
4745 this .shouldSort = true ,
48- SorterFn <T > sortFn,
46+ SorterFn <T >? sortFn,
4947 this .tokenize = false ,
5048 this .matchAllTokens = false ,
5149 this .verbose = false ,
@@ -113,24 +111,42 @@ class FuzzyOptions<T> {
113111 /// characters before searching.
114112 final bool shouldNormalize;
115113
116- /// Merge two options instances. Useful for overriding just some options.
117- FuzzyOptions <T > mergeWith (FuzzyOptions <T > options) => FuzzyOptions (
118- location: options? .location ?? location,
119- distance: options? .distance ?? distance,
120- threshold: options? .threshold ?? threshold,
121- maxPatternLength: options? .maxPatternLength ?? maxPatternLength,
122- isCaseSensitive: options? .isCaseSensitive ?? isCaseSensitive,
123- tokenSeparator: options? .tokenSeparator ?? tokenSeparator,
124- minTokenCharLength: options? .minTokenCharLength ?? minTokenCharLength,
125- findAllMatches: options? .findAllMatches ?? findAllMatches,
126- minMatchCharLength: options? .minMatchCharLength ?? minMatchCharLength,
127- keys: options? .keys ?? keys,
128- shouldSort: options? .shouldSort ?? shouldSort,
129- sortFn: options? .sortFn ?? sortFn,
130- tokenize: options? .tokenize ?? tokenize,
131- matchAllTokens: options? .matchAllTokens ?? matchAllTokens,
132- verbose: options? .verbose ?? verbose,
133- shouldNormalize: options? .shouldNormalize ?? shouldNormalize,
114+ /// Copy these options with some modifications.
115+ FuzzyOptions <T > copyWith ({
116+ int ? location,
117+ int ? distance,
118+ double ? threshold,
119+ int ? maxPatternLength,
120+ bool ? isCaseSensitive,
121+ Pattern ? tokenSeparator,
122+ bool ? findAllMatches,
123+ int ? minTokenCharLength,
124+ int ? minMatchCharLength,
125+ List <WeightedKey <T >>? keys,
126+ bool ? shouldSort,
127+ SorterFn <T >? sortFn,
128+ bool ? tokenize,
129+ bool ? matchAllTokens,
130+ bool ? verbose,
131+ bool ? shouldNormalize,
132+ }) =>
133+ FuzzyOptions (
134+ location: location ?? this .location,
135+ distance: distance ?? this .distance,
136+ threshold: threshold ?? this .threshold,
137+ maxPatternLength: maxPatternLength ?? this .maxPatternLength,
138+ isCaseSensitive: isCaseSensitive ?? this .isCaseSensitive,
139+ tokenSeparator: tokenSeparator ?? this .tokenSeparator,
140+ findAllMatches: findAllMatches ?? this .findAllMatches,
141+ minTokenCharLength: minTokenCharLength ?? this .minTokenCharLength,
142+ minMatchCharLength: minMatchCharLength ?? this .minMatchCharLength,
143+ keys: keys ?? this .keys,
144+ shouldSort: shouldSort ?? this .shouldSort,
145+ sortFn: sortFn ?? this .sortFn,
146+ tokenize: tokenize ?? this .tokenize,
147+ matchAllTokens: matchAllTokens ?? this .matchAllTokens,
148+ verbose: verbose ?? this .verbose,
149+ shouldNormalize: shouldNormalize ?? this .shouldNormalize,
134150 );
135151
136152 static List <WeightedKey <T >> _normalizeWeights <T >(List <WeightedKey <T >> keys) {
0 commit comments