fuzzyMatches static method

bool fuzzyMatches(
  1. String searchText,
  2. String targetText
)

Performs fuzzy search by checking if all words in search text are present in target

Implementation

static bool fuzzyMatches(String searchText, String targetText) {
  if (searchText.isEmpty) return true;
  if (targetText.isEmpty) return false;

  final normalizedSearch = normalizeForSearch(searchText);
  final normalizedTarget = normalizeForSearch(targetText);

  final searchWords = normalizedSearch.split(' ').where((word) => word.isNotEmpty).toList();
  if (searchWords.isEmpty) return true;

  // Check if all search words are present as complete words in the target
  return searchWords.every((word) =>
      RegExp(r'\b' + RegExp.escape(word) + r'\b').hasMatch(normalizedTarget)
  );
}