Пример #1
0
        private void search_input_TextChanged(object sender, EventArgs e)

        /*Event trigger when a text input into search text box
         * Used to catch the word from input string and call suggestion feature*/
        {
            //Identify the start position of latest word in search text box
            int wordEndPosition = search_input.SelectionStart;
            int currentPosition = wordEndPosition;

            while (currentPosition > 0 && search_input.Text[currentPosition - 1] != ' ')
            {
                currentPosition--;
            }

            //Read out the last word
            string word = search_input.Text.Substring(currentPosition, wordEndPosition - currentPosition);

            //Process if the read word is not whitespace/null and is more than 2 characters.
            if (!String.IsNullOrWhiteSpace(word) && (word.Length > 2))
            {
                //Get the suggest word(s) from the original word
                string[] suggestword = LuceneSearch_app.AutoCompleteSuggestion(word);
                //Fit 3 words at most into the suggest word labels
                switch (suggestword.Length)
                {
                case 1:
                    autoText1.Text          = suggestword[0];
                    autoText1.Visible       = true;
                    SpellCheckLabel.Visible = true;
                    break;

                case 2:
                    autoText1.Text          = suggestword[0];
                    autoText1.Visible       = true;
                    autoText2.Text          = suggestword[1];
                    autoText2.Visible       = true;
                    SpellCheckLabel.Visible = true;
                    break;

                case 3:
                    autoText1.Text          = suggestword[0];
                    autoText1.Visible       = true;
                    autoText2.Text          = suggestword[1];
                    autoText2.Visible       = true;
                    autoText3.Text          = suggestword[2];
                    autoText3.Visible       = true;
                    SpellCheckLabel.Visible = true;
                    break;

                default:
                    break;
                }
            }
            else
            {
                //Disable all labels when there is nothing to suggest.
                autoText1.Visible       = false;
                autoText2.Visible       = false;
                autoText3.Visible       = false;
                autoText1.Text          = null;
                SpellCheckLabel.Visible = false;
                search_query.Visible    = false;
            }
        }