// Create results for trec_val evaluation
        private void AutoParsing_Click(object sender, EventArgs e)
        {
            saveInfoDialog.Filter = "Text File|*.txt";
            saveInfoDialog.Title  = "Save Text File";

            stopwatch = new Stopwatch();
            string totalSearchTime = null;

            // Check if it has already indexed
            if (indexingState == true)
            {
                if (saveInfoDialog.ShowDialog() == DialogResult.OK)
                {
                    int    index      = 0;
                    string documentID = null;

                    // Get speficied file path and topic ID
                    string path = saveInfoDialog.FileName;

                    List <string> infoID    = new List <string>();
                    List <string> infoNeeds = new List <string>();

                    // Preprocess the document
                    string[] delimeters = { ".I ", ".D" };
                    string[] infoTokens = Resource.cran_information_needs.Split(delimeters, StringSplitOptions.RemoveEmptyEntries);
                    for (int i = 0; i < infoTokens.Length; i++)
                    {
                        if (i % 2 == 0)
                        {
                            infoID.Add(infoTokens[i]);
                        }
                        else
                        {
                            infoNeeds.Add(infoTokens[i]);
                        }
                    }

                    // Print out the results across each information needs
                    foreach (var infoNeed in infoNeeds)
                    {
                        int rank = 0;
                        searching = new SearchingClass();

                        stopwatch.Start();
                        TopDocs infoResults = searching.SearchIndex(IndexingClass.luceneIndexDirectory, IndexingClass.analyzer, infoNeed, PhraseFormCheckbox.Checked, StemCheckBox.Checked, QueryExpansionCheckBox.Checked);
                        stopwatch.Stop();
                        searching.ClearnUpSearcher();

                        // Check whether the specified file is already exists or not
                        if (File.Exists(path))
                        {
                            // Append new results to existing file if it is true
                            using (StreamWriter stwriter = File.AppendText(path))
                            {
                                foreach (ScoreDoc scorDoc in infoResults.ScoreDocs)
                                {
                                    rank++;
                                    // Use searcher to acquire doucment ID
                                    using (IndexSearcher searcher = new IndexSearcher(IndexingClass.luceneIndexDirectory))
                                    {
                                        documentID = searcher.Doc(scorDoc.Doc).Get(IndexingClass.FieldDOC_ID).ToString();
                                        documentID = documentID.Split(new[] { '\n' })[0];
                                    }

                                    // Write to the file
                                    stwriter.WriteLine("{0,-4} {1,-4} {2,-7} {3,-5} {4,-11} {5}", infoID[index].Substring(0, 3), "Q0", documentID, rank, scorDoc.Score, "n9843329_n9861718_n5767032_HelloWorldTeam");
                                }
                            }
                        }
                        else
                        {
                            using (StreamWriter stwriter = new StreamWriter(File.Create(path)))
                            {
                                foreach (ScoreDoc scorDoc in infoResults.ScoreDocs)
                                {
                                    rank++;
                                    using (IndexSearcher searcher = new IndexSearcher(IndexingClass.luceneIndexDirectory))
                                    {
                                        documentID = searcher.Doc(scorDoc.Doc).Get(IndexingClass.FieldDOC_ID).ToString();
                                        documentID = documentID.Split(new[] { '\n' })[0];
                                    }
                                    stwriter.WriteLine("{0,-4} {1,-4} {2,-7} {3,-5} {4,-11} {5}", infoID[index].Substring(0, 3), "Q0", documentID, rank, scorDoc.Score, "n9843329_n9861718_n5767032_HelloWorldTeam");
                                }
                            }
                        }
                        index++;
                    }
                }
            }
            else
            {
                MessageBox.Show("You need to do indexing before generating the results");
            }

            MessageBox.Show(stopwatch.Elapsed.ToString(), "Searching time");
        }
        private void SearchButton_Click(object sender, EventArgs e)
        {
            // Check if the document has already indexed
            if (indexingState == true)
            {
                // Check if the query is empty
                if (!(QueryEnter.Text == ""))
                {
                    // Determine whether the query should be remain orginal form
                    if (PhraseFormCheckbox.Checked)
                    {
                        inputQuery = "\"" + QueryEnter.Text + "\"";
                    }
                    else
                    {
                        inputQuery = QueryEnter.Text;
                    }

                    searching = new SearchingClass();
                    stopwatch = new Stopwatch();

                    // Search the query against the index, the default return size is set to be 30
                    // retrieve the searching result TopDocs object
                    stopwatch.Restart();
                    results = searching.SearchIndex(IndexingClass.luceneIndexDirectory, IndexingClass.analyzer, inputQuery, PhraseFormCheckbox.Checked, StemCheckBox.Checked, QueryExpansionCheckBox.Checked);
                    stopwatch.Stop();

                    // Display Searching info
                    if (QueryExpansionCheckBox.Checked && wordNet.IsLoaded)
                    {
                        if (SearchingClass.finalExpandedQueryList.Count == 0)
                        {
                            FinalQueryLabel.Text = "Final query: " + string.Join(", ", SearchingClass.queryList);
                        }
                        else
                        {
                            FinalQueryLabel.Text = "Final query: " + string.Join(", ", SearchingClass.finalExpandedQueryList);
                        }
                    }
                    else
                    {
                        FinalQueryLabel.Text = "Final query: " + string.Join(", ", SearchingClass.queryList);
                    }
                    SearchingTimeLabel.Text = "Searching time: " + stopwatch.Elapsed.ToString();
                    TotalHitsLabel.Text     = "Total hits: " + results.TotalHits;

                    // Acquire the ranked documents and display the results and clean up searcher
                    ranked_docs = searching.Get_doc(results);
                    searching.ClearnUpSearcher();
                    DisplayResult(results, ranked_docs, displayBatch = 0);

                    // Only show these button when totalhits is not zero
                    if (results.TotalHits != 0)
                    {
                        DisplayItenButton.Show();
                        SaveButton.Show();
                        NextButton.Show();
                    }
                    else
                    {
                        PreviousButton.Hide();
                        NextButton.Hide();
                        SaveButton.Hide();
                        DisplayItenButton.Hide();
                    }
                }
                else
                {
                    MessageBox.Show("You need to specify your query");
                }
            }
            else
            {
                MessageBox.Show("You need to do indexing before seaching");
            }
        }