1

I have an ICollectionView bound to a DataGrid which contains 1 million items and should be filtered as user types in a search text box. Due to the large number of items, filtering algorithm should be performance friendly.

This is my current string comparison (some part of filtering method):

static bool AreEqual(string str1, string str2)
{
    var compareInfo = CultureInfo.InvariantCulture.CompareInfo;
    bool result = compareInfo.IndexOf(str1, str2, CompareOptions.IgnoreNonSpace) > -1;
    return result;
}

The CompareOptions.IgnoreNonSpace ignore diacritics very well but ignores half space with Unicode \u200c too, which is not what I want. I just want to ignore diacritics.

bool compare1 = AreEqual("آبی","آبی");  //true, It's Okay.
bool compare2 = AreEqual("آبی", "ابی"); //true. It's Okay.
bool compare3 = AreEqual("آبی", "آب‌ی"); //true. This is not what I want. It should return false
bool compare4 = AreEqual("آبی", "اب‌ی"); //true. This is not what I want. It should return false.

Since, the performance is critical, I can't remove diacritics with normalizing strings before comparison.

One more question:

I want to filter CollectionView, in a way that, first 10 results will be returned and continue to search in a background thread while user is reading current DataGrid viewport. When user scrolls the DataGrid, show next 10 results which are filtered in the background thread. I don't want user waits for CollectionView to finish filtering 1 million items.

Ayub
  • 2,345
  • 27
  • 29
  • You can try to use [data virtualization](https://learn.microsoft.com/en-us/dotnet/framework/wpf/advanced/optimizing-performance-controls) for the large set of data – Pavel Anikhouski Feb 20 '20 at 20:21
  • I store normalized strings with original in the same dataset. And make normalization only for user-typed text and compare to already normalized data. In my case there's 20000 values, not a large set. But works like a charm. – aepot Feb 22 '20 at 18:28
  • @aepot It's type of Data Redundancy which I hate :) – Ayub Feb 22 '20 at 19:13
  • @PavelAnikhouski What I want is a little complex and I'm looking for a code sample to implement my algorithm. I know [IAsyncEnumerable](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.iasyncenumerable-1?view=netcore-3.1) help me, but merging it with a UI and data template is more complex than my experience. – Ayub Feb 22 '20 at 19:19

0 Answers0