Beispiel #1
0
        /// <summary>
        /// Converts a search term to Double Metaphone hash code suitable for fuzzy text searching.
        /// </summary>
        /// <param name="term">A single or multiple word search term</param>
        public static string ToDoubleMetaphoneHash(this string term)
        {
            return(string.Join(" ", DoubleMetaphone.GetKeys(RemoveDiacritics(term))));

            string RemoveDiacritics(string text)
            {
                var    sb  = new StringBuilder();
                string str = text.Normalize(NormalizationForm.FormD);

                for (int i = 0; i < str.Length; i++)
                {
                    char c = str[i];
                    if (CharUnicodeInfo.GetUnicodeCategory(c) != UnicodeCategory.NonSpacingMark)
                    {
                        sb.Append(c);
                    }
                }
                return(sb.ToString().Normalize(NormalizationForm.FormC));
            }
        }
 /// <summary>
 /// Converts a search term to Double Metaphone hash code suitable for fuzzy text searching.
 /// </summary>
 /// <param name="term">A single or multiple word search term</param>
 public static string ToDoubleMetaphoneHash(this string term)
 {
     return(string.Join(" ", DoubleMetaphone.GetKeys(term)));
 }