tokenSortRatio function

double tokenSortRatio(
  1. String a,
  2. String b
)

fuzzywuzzy-style token-sort ratio: ratio after each string's tokens are lowercased, sorted, and rejoined, in [0, 1].

Makes the comparison order-insensitive, so 'York New' matches 'New York' fully — the right metric when word order varies but content does not (names entered "First Last" vs "Last First"). Audited: 2026-06-12 11:26 EDT

Implementation

double tokenSortRatio(String a, String b) {
  final List<String> ta = _fuzzyTokens(a)..sort();
  final List<String> tb = _fuzzyTokens(b)..sort();

  return LevenshteinUtils.ratio(ta.join(' '), tb.join(' '));
}