简体   繁体   中英

Efficient Auto-Complete TextBox

I am implementing a Search function that works just like Google in my Windows Forms Application. I have implemented the Auto Complete as follows:

private void MemberSearch()
{
    // Name Search
    ConnectionClass.GetInstance().connection_string = Properties.Settings.Default.MindMuscleConnectionString;
    ConnectionClass.GetInstance().Sql = "select MemberInfo.memberName from MemberInfo";
    DataSet ds = ConnectionClass.GetInstance().GetConnection;
    AutoCompleteStringCollection name = new AutoCompleteStringCollection();
    for (int x = 0; x < ds.Tables[0].Rows.Count; x++)
    {
        name.Add(ds.Tables[0].Rows[x].ItemArray.GetValue(0).ToString());
    }
    memberNameSearchTxtBox.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
    memberNameSearchTxtBox.AutoCompleteSource = AutoCompleteSource.CustomSource;
    memberNameSearchTxtBox.AutoCompleteCustomSource = name;
    // ID Search
    ConnectionClass.GetInstance().Sql = "select MemberInfo.memberID from MemberInfo";
    ds = ConnectionClass.GetInstance().GetConnection;
    AutoCompleteStringCollection id = new AutoCompleteStringCollection();
    for (int x = 0; x < ds.Tables[0].Rows.Count; x++)
    {
        id.Add(ds.Tables[0].Rows[x].ItemArray.GetValue(0).ToString());
    }
    memberIdSearchTxtBox.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
    memberIdSearchTxtBox.AutoCompleteSource = AutoCompleteSource.CustomSource;
    memberIdSearchTxtBox.AutoCompleteCustomSource = id;
}

Question:

While this auto-complete works just fine, I am thinking that if the number of records are in millions or more, Will this method work fine? I am calling this method on the Form Load Event. Is there a more efficient way of doing this?

Any system that tries to offer millions of records while the user is typing in characters will break down. And if you preload it, that is access it unfiltered it will take ages and lots of RAM to start..

So you should try to add a gauging algorithm to your data. This would usually be a combination of several things. Two things come to mind immediately:

  • The number of times the record was accepted as the correct one will add to the gauging value
  • The timespan without being accepted will subtract from the gauging value

You may want to google Google autocomplete algorithm to get more ideas..

Instead of selecting everything you would then

  • Select with an order by gauge-field
  • Select with a where clause to get only the best records
  • Successively lower the gauge threshold until the result set is reasonably large

I assume you use the Telerik AutoCompleteBox? A visit to their forums may also help..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM