vain0x / DotNetKit.Wpf.AutoCompleteComboBox

ComboBox with filtering (auto-complete) for WPF
MIT License
71 stars 26 forks source link

Feature request: customize suggestions order #2

Open AsValeO opened 7 years ago

AsValeO commented 7 years ago

vain0, thank you for this piece of code. ComboBox is brilliant and perfectly works out-of-box. I offer to improve suggestions orger. For example: Text input: it Current result:

git
item
iterate
community

Result requested: strings starting with it placed on the top of list:

item
iterate
git
community

Is there a way to add such tweak?

vain0x commented 7 years ago

Hello. Your suggestion looks good! Thank you.

AsValeO commented 7 years ago

Take a look:

public virtual Func<object, bool> GetFilter(string query, Func<object, string> stringFromItem)
        {
            return item =>

            //! Filter one
                    stringFromItem(item).IndexOf(query, StringComparison.OrdinalIgnoreCase) >= 0 ||

            //! Filter two
            stringFromItem(item).IndexOf(Transliteration.LatinToCyrillyc(query, Language.Russian),
                StringComparison.OrdinalIgnoreCase) >= 0;
        }

Here we got 2 filters. Replacing Func<object, bool> GetFilter with List<Func<object, bool>> GetFilters gives us possibility to order results by filters.

vain0x commented 7 years ago

I think GetFilters is not flexible. It can be generalized to:

public virtual Func<object, double> Priority(string query, Func<object, string> text)
{
    return item =>
    {
        if (filter1(query, text)(item)) return 0;
        if (filter2(query, text)(item)) return 1;
        return double.MaxValue;
    };
}

I'm facing a problem that there is no way to sort Items, the backing collection of the dropdown list, with an arbitrary comparer. We need to sort items by properties with default comparers; or sort ItemsSource instead. So there are two options:

I don't choose (A) because it's inefficient and difficult to use. I have hesitation in implementing (B). Hmm...

AsValeO commented 7 years ago

I'm sorry, but I can't dig deep into AutoCompleteComboBox mechanics and help with this feature right now.