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:
You may want to google Google autocomplete algorithm to get more ideas..
Instead of selecting everything you would then
order by gauge-field
where
clause to get only the best recordsI assume you use the Telerik AutoCompleteBox? A visit to their forums may also help..