normalizeForSearch static method

String normalizeForSearch(
  1. String text
)

Normalizes text for search by:

  • Converting to lowercase
  • Removing diacritics/accents
  • Removing extra whitespace
  • Removing special characters (keeping alphanumeric and basic punctuation)

Implementation

static String normalizeForSearch(String text) {
  if (text.isEmpty) return text;

  return removeDiacritics(text)
      .toLowerCase()
      .trim()
      .replaceAll(RegExp(r'\s+'), ' ') // Replace multiple spaces with single space
      .replaceAll(RegExp(r'[^\w\s\-\.]'), ' ') // Replace special chars with spaces
      .replaceAll(RegExp(r'\s+'), ' ') // Clean up spaces again
      .trim();
}