예제 #1
0
        /*
         *  Search collection for ALL query terms using the terms to iterate over
         */
        private void Search_Click(object sender, EventArgs e)
        {
            string folderPath = FolderOutput.Text;              // get the folderPath from output TextBox

            string[] searchTerms = SearchTerms.Text.Split(' '); // Get the search terms


            // check a folderPath is inputted and check a search query is inputted
            if (folderPath != "" && !(searchTerms.Length < 2 && searchTerms[0] == ""))
            {
                FileOutput.Items.Clear(); // clear the file ListBox
                FrequencyBox.Clear();     // clear the frequency TextBox

                // start the timer on a search, this timer includes generating Hashtable,
                // searching the collection, and querying Hashtable for query frequencies
                var watch = System.Diagnostics.Stopwatch.StartNew();
                // increase searchCount
                searchCount++;
                // reset fileCount
                fileCount = 0;

                /*
                 * Modularised methods to get querys
                 */

                Hashtable wf = indexUtils.GetHashtable(folderPath); //the Hashtable generated on search.

                // Get the files containing the search terms using iterating over terms method and output
                List <string> containFiles = searchUtil.GetFilesContainingTermsByTerms(folderPath, searchTerms,
                                                                                       CheckSynonyms.Checked, newWordsDataSet);
                foreach (string file in containFiles)
                {
                    FileOutput.Items.Add(file);
                    fileCount++;
                }

                /*
                 *  Output from the Hashtable - query terms and their frequency, plus the
                 *  word in the entire collection with the highest frequency
                 */

                // output the maximum frequency word
                MostFrequentBox.Text = indexUtils.GetMax(wf);
                // output the query terms frequency (if they exist)
                FrequencyBox.Text = indexUtils.QueryFrequency(wf, searchTerms);

                // end of the search process
                watch.Stop();
                // get the results of stopWatch.
                var elapsedTime = watch.ElapsedMilliseconds;
                totalSearchTime += elapsedTime;
                // Output search times and number of found files to the Form
                SearchTime.Text  = "Search Time: " + elapsedTime.ToString() + "ms";
                AverageTime.Text = "Average Time: " + (totalSearchTime / searchCount).ToString("0") + "ms";
                FoundFiles.Text  = "Files Found: " + fileCount;
            }
            else
            {
                if (folderPath == "")
                {
                    MessageBox.Show("No folder has been selected!");
                }
                else
                {
                    MessageBox.Show("No search query entered");
                }
            }
        }
예제 #2
0
        /*
         * Search collection for ALL the query terms iterating over the files
         * This is now searching the Inverted Index
         */
        private void SearchByFiles_Click(object sender, EventArgs e)
        {
            string folderPath = FolderOutput.Text;                    // get the folderPath from output TextBox

            string[]      searchTerms  = SearchTerms.Text.Split(' '); // Get the search terms
            List <string> containFiles = new List <string>();

            // check a folderPath is inputted and check a search query is inputted
            if (folderPath != "" && !(searchTerms.Length < 2 && searchTerms[0] == ""))
            {
                // checks if thread building index is running
                if (thread.IsAlive)
                {
                    MessageBox.Show("The index is currently rebuilding. Try again later");
                }
                else
                {
                    FileOutput.Items.Clear(); // clear the file ListBox
                    FrequencyBox.Clear();     // clear the frequency TextBox

                    // start the timer on a search, this timer includes generating Hashtable,
                    // searching the collection, and querying Hashtable for query frequencies
                    var watch = System.Diagnostics.Stopwatch.StartNew();
                    // increase searchCount
                    searchCount++;
                    // reset fileCount
                    fileCount = 0;

                    /*
                     * Modularised methods to get querys
                     */

                    //Check the inverted index is created
                    if (!isIndexCreated)
                    {
                        // No index exists so create one first.
                        CreateInvertedIndex_Click(sender, e);
                    }
                    else
                    {
                        // search for the files in the index matching the terms
                        searchInvertedIndex(searchTerms);
                    }

                    // stop the watch
                    watch.Stop();
                    // get the results of stopWatch.
                    var elapsedTime = watch.ElapsedMilliseconds;
                    totalSearchTime += elapsedTime;
                    // Output search times and number of found files to the Form
                    SearchTime.Text  = "Search Time: " + elapsedTime.ToString() + "ms";
                    AverageTime.Text = "Average Time: " + (totalSearchTime / searchCount).ToString("0") + "ms";
                    FoundFiles.Text  = "Files Found: " + fileCount;
                }
            }
            else
            {
                if (folderPath == "")
                {
                    MessageBox.Show("No folder has been selected!");
                }
                else
                {
                    MessageBox.Show("No search query entered");
                }
            }
        }