Пример #1
0
        private string QueryExpansion(string input)
        /*Expand the query from original word to synonym word list based on WORDNET library*/
        {
            string[] delim  = { " " };
            string[] words  = input.Split(delim, StringSplitOptions.RemoveEmptyEntries);
            Regex    rgx    = new Regex("[^a-zA-z]");
            string   result = input;

            foreach (string word in words)
            {
                //get expansion here
                List <string> synonyms = LuceneSearch_app.GetSynonym(stemmer.stemTerm(rgx.Replace(word, "")));
                string        temp     = "";

                foreach (string synonym in synonyms)
                {
                    temp += " " + synonym;
                }

                if (word.StartsWith("\""))
                {
                    result += temp;
                }
                else
                {
                    result = result.Replace(word, (word + "^10" + temp));
                }
            }


            return(result);
        }
Пример #2
0
        //FUNCTIONS TO CONVERT INFORMATION NEEDS TO QUERY
        private string RemoveStopWords(string input)
        /*Remove the stop word from the input query string*/
        {
            string result = LuceneSearch_app.GetProcessedQueryText(input, true);

            return(result);
        }
Пример #3
0
        private void ShowResults(int index)
        /*Put the search result into data grid area*/
        {
            List <string[]> results = LuceneSearch_app.GetResultCollection(index);

            dataGridView.Rows.Clear();
            foreach (string[] item in results)
            {
                item[4] = getFirstSentence(item[4]);
                dataGridView.Rows.Add(item);
            }
        }
Пример #4
0
        private void saveBtn_Click(object sender, EventArgs e)

        /*Event trigger when Save button is clicked
         * Save the result of query into a text file. require a querry ID is input into querry ID text box
         * It will append into an existing file or create a new file is given name is not available*/
        {
            int queryId;
            //Parse the query ID from query text box
            bool result = Int32.TryParse(queryIdLabel.Text, out queryId);

            if (result)
            {
                //result is an integer number then check if there is valid search result
                if (LuceneSearch_app.ScoreDocs != null & LuceneSearch_app.ScoreDocs.Length > 0)
                {
                    SaveFileDialog saveFileDialog1 = new SaveFileDialog();
                    //Identify file extension filter
                    saveFileDialog1.Filter           = "txt files (*.txt)|*.txt";
                    saveFileDialog1.FilterIndex      = 2;
                    saveFileDialog1.RestoreDirectory = true;
                    saveFileDialog1.OverwritePrompt  = false;

                    if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                    {
                        //save file with given queryID
                        string path = saveFileDialog1.FileName;
                        LuceneSearch_app.AppendSearchResult(path, queryId);
                    }
                }
            }
            else
            {
                //show warning if no suitable query ID provided.
                MessageBox.Show("Please enter query identification",
                                "About",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation,
                                MessageBoxDefaultButton.Button1);
            }
        }
Пример #5
0
        private void search_btn_Click(object sender, EventArgs e)

        /*Handle the event when clicking search button
         * Search main routine*/
        {
            dataGridView.Rows.Clear();
            search_query.Visible = true;
            if (string.IsNullOrEmpty(search_input.Text))
            {
                next_button.Enabled     = false;
                LastButton.Enabled      = false;
                SearchTimeLabel.Visible = false;
                page_label.Visible      = false;
                search_query.Text       = "> Status: Please input a query";
                return;
            }
            string    query     = search_input.Text;
            Stopwatch stopwatch = Stopwatch.StartNew();

            if (!Skip_process.Checked)
            {
                query = PreProcessQuery(query);
            }
            if (string.IsNullOrEmpty(query.Trim()))
            {
                next_button.Enabled     = false;
                LastButton.Enabled      = false;
                SearchTimeLabel.Visible = false;
                page_label.Visible      = false;
                search_query.Text       = "> Status: All of input is filtered by pre-processsing";
                return;
            }
            search_query.Text = S_query_ori + "\n" + query;
            totalPage         = LuceneSearch_app.Search(query, SearchFieldCB.SelectedItem.ToString());
            if (totalPage == 0)
            {
                currentPage         = 0;
                prev_button.Enabled = false;
                next_button.Enabled = false;
                FirstButton.Enabled = false;
                LastButton.Enabled  = false;
            }
            else
            {
                currentPage         = 1;
                prev_button.Enabled = false;
                next_button.Enabled = false;
                LastButton.Enabled  = false;
                FirstButton.Enabled = false;
                if (totalPage > 1)
                {
                    next_button.Enabled = true;
                    LastButton.Enabled  = true;
                }
                ShowResults(currentPage);
            }
            stopwatch.Stop();
            SearchTimeLabel.Text = string.Format("Found {0} result(s) in about {1}ms",
                                                 LuceneSearch_app.ScoreDocs.Length, stopwatch.ElapsedMilliseconds);
            SearchTimeLabel.Visible = true;
            UpdatePageLabel();
        }
Пример #6
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;
            }
        }