Example #1
0
 public Form1()
 {
     InitializeComponent();
     AutoComplete.ImportWords();
     AutoComplete.ImportQueries();
     listBox1.Hide();
 }
Example #2
0
        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            string userInput = textBox1.Text.ToLower();
            string prev      = "";
            string current   = "";
            int    i         = 0;

            foreach (char x in userInput)
            {
                if (x == ' ')
                {
                    if (current == "")
                    {
                        continue;
                    }
                    prev    = current;
                    current = "";
                    i++;
                    continue;
                }
                current += x;
            }
            if (current.Length == 0)
            {
                current = prev;
                i--;
            }
            Suggestions = AutoComplete.getSuggestions(current);
            if (Suggestions != null)
            {
                listBox1.Items.Clear();
                if (radioButton1.Checked)
                {
                    Suggestions = Sorting.mergeSort(Suggestions);
                }
                else
                {
                    Sorting.bubbleSort(Suggestions);
                }
                foreach (Query q in Suggestions)
                {
                    if (q.query.Length >= userInput.Length)
                    {
                        if (q.index == i && q.query.Substring(0, userInput.Length) == userInput)
                        {
                            listBox1.Items.Add(q.query);
                        }
                    }
                }
                if (listBox1.Items.Count == 0)
                {
                    foreach (Query q in Suggestions)
                    {
                        listBox1.Items.Add(q.query);
                    }
                }
                if (listBox1.Items.Count > 0)
                {
                    listBox1.Show();
                }
            }
            else
            {
                listBox1.Items.Clear();
                listBox1.Hide();
            }
        }
Example #3
0
        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            string userInput = textBox1.Text.ToLower();

            if (userInput.EndsWith(" "))
            {
                return;
            }
            string prev    = "";
            string current = "";
            byte   i       = 0;

            foreach (char x in userInput)
            {
                if (x == ' ')
                {
                    if (current == "")
                    {
                        continue;
                    }
                    prev    = current;
                    current = "";
                    i++;
                    continue;
                }
                current += x;
            }
            if (current.Length == 0)
            {
                i--;
            }
            Suggestions = AutoComplete.GetSuggestions(userInput);
            if (AutoComplete.GetCorrectedWords() != "" && AutoComplete.GetCorrectedWords() != null)
            {
                userInput = AutoComplete.GetCorrectedWords();
            }
            if (Suggestions != null)
            {
                listBox1.Items.Clear();
                if (radioButton1.Checked)
                {
                    Suggestions = Sorting.MergeSort(Suggestions);
                }
                else
                {
                    Sorting.BubbleSort(Suggestions);
                }
                foreach (int n in Suggestions)
                {
                    if (AutoComplete.myQueries[n].query.Length >= userInput.Length)
                    {
                        if (AutoComplete.myQueries[n].index.ContainsKey(i) && AutoComplete.myQueries[n].index[i] && AutoComplete.myQueries[n].query.Substring(0, userInput.Length) == userInput)
                        {
                            listBox1.Items.Add(AutoComplete.myQueries[n].query);
                        }
                    }
                    if (listBox1.Items.Count == 10)
                    {
                        break;
                    }
                }
                if (listBox1.Items.Count == 0)
                {
                    foreach (int n in Suggestions)
                    {
                        if (listBox1.Items.Count == 10)
                        {
                            break;
                        }
                        listBox1.Items.Add(AutoComplete.myQueries[n].query);
                    }
                }
                if (listBox1.Items.Count > 0)
                {
                    listBox1.Show();
                }
            }
            else
            {
                listBox1.Items.Clear();
                listBox1.Hide();
            }
        }