This is a migrated thread and some comments may be shown as answers.

Using AutoCompleteBox without diacritics

5 Answers 42 Views
AutoCompleteBox
This is a migrated thread and some comments may be shown as answers.
Richard
Top achievements
Rank 1
Richard asked on 23 Sep 2013, 02:17 PM
Hi,

is it possible to use autocomplete without diacritics? For example when I have AutoCompleteBox.ItemsSource with ViewModels containing property Name (one contains Name == "Šířka" for example) and I would like to search item with entered word in antocompletebox sir/sirk/Širk/Šíř etc.

Thank you for your help.

5 Answers, 1 is accepted

Sort by
0
Vladi
Telerik team
answered on 26 Sep 2013, 07:59 AM
Hi,

In the current version of RadAutoCompleteBox control the described behavior when the control searches through its items is not a built-in feature. The control's TextSearchMode could be set to Contains, ContainsCaseSensitive, StartsWith, StartsWithCaseSensitive, the default value is StartsWith. In those modes the searching compares the symbols exactly and do not replace specific symbols with others.

You could create a custom FilteringBehavior and override its FindMatchingItems method. In that method implement a custom logic that will change the searchText (which is the input text) before passing it to the base.FindMatchingItems() method that returns the matched items. More information about custom FilteringBehavior could be found here.

Regards,
Vladi
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Jc
Top achievements
Rank 1
answered on 17 Apr 2014, 07:21 AM
Hello,

I've got approximately the same problem, about search without accents, I'd like to remove diacritics on the search word, and also on the list of items searched, for example, if I type "greg", i'd like to find "Grégory".
Would you have any peace of sample code to achieve this?
Would look something like this:
public static string RemoveDiacritics(this string s)
        {
            String normalizedString = s.Normalize(NormalizationForm.FormD);
            StringBuilder stringBuilder = new StringBuilder();
 
            for (int i = 0; i < normalizedString.Length; i++)
            {
                Char c = normalizedString[i];
                if (CharUnicodeInfo.GetUnicodeCategory(c) != UnicodeCategory.NonSpacingMark)
                    stringBuilder.Append(c);
            }
            return stringBuilder.ToString();
        }
 
 
 
 public class WithoutDiacriticsFilteringBehavior : FilteringBehavior
    {
        public override IEnumerable<object> FindMatchingItems(string searchText, IList items, IEnumerable<object> escapedItems, string textSearchPath, TextSearchMode textSearchMode)
        {
            searchText = searchText.ToLower().RemoveDiacritics();
            ///override this to remove diacritics in the search:
            return FindMatchingItemsWithoutDiacritics(searchText, items, escapedItems, textSearchPath, textSearchMode) as IEnumerable<object>;
 
            
        }
    }


Thank you.
Kind regards,
JC



0
Rosen Vladimirov
Telerik team
answered on 17 Apr 2014, 10:34 AM
Hello JC,

I've created a sample project to show you one way to achieve this. As your ItemsSource will contain items with diacritics, you will have to modify the items collection that is passed to the FindMatchingItems method. In the sample I've used the method you've suggested (RemoveDiacritics) to modify all strings from the items source directly in the FindMatchingItems and when a match is found, I return back the original item from the items source.

Please give it a try and inform us in case you have any problems or concerns.

Regards,
Rosen Vladimirov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Jc
Top achievements
Rank 1
answered on 17 Apr 2014, 11:14 AM
Your sample seems fine, but in my case, the IList items is not a list of string bue a list of complex objects, a List<User>, searching on the User.FullName. So it won't work for me. I could still implement a specific Behavior for User object, but as I have other types of object, I'd like this behavior to be generic.
Any idea?
Thank's for your help.
KR,
JC
0
Rosen Vladimirov
Telerik team
answered on 17 Apr 2014, 12:28 PM
Hello JC,

I've modified my project to use reflection and get the value of the search property based on the TextSearchPath. Please find it attached and inform us in case you have any problems or concerns.

Regards,
Rosen Vladimirov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
AutoCompleteBox
Asked by
Richard
Top achievements
Rank 1
Answers by
Vladi
Telerik team
Jc
Top achievements
Rank 1
Rosen Vladimirov
Telerik team
Share this question
or