/* * Takes input of file path and search terms. * Splits search terms into an array, and if include * synonyms is checked, fires method for setting * terms and synonyms (newSearch varible). * Calls SearchDirectory, runs timer while that is running, * and outputs time taken to form. * Fires the method to populate form with returned * data. * @param object sender, EventArgs e */ private void Searchbut_Click(object sender, EventArgs e) { if (rebuild)//fires if inverted index is being refreshed { MessageBox.Show("Currently unavailable. Please try again later"); } else { if (SelectFolder.Text == "")//error handling for no file path selected { MessageBox.Show("Please select a file and try again"); } if (SearchTerms.Text == "")//error handling for no search terms entered. { MessageBox.Show("Please a enter a search term, and try again"); } FilePathOutput.Items.Clear(); //clears list box. if (SearchTerms.Text != "" && SelectFolder.Text != "") //fires if there is a filepath and search term entered. { numSearch = numSearch + 1; //adds one to variable holding number of searches. Used for average time. searchTerms = SearchTerms.Text.Split(',', ' '); //splits the search terms at space or comma for (int i = 0; i < searchTerms.Length; i++) { searchTerms[i] = searchTerms[i].ToLower();//sets all entered search terms to lower case, to match the database. } if (IncludeSynonyms.Checked) { DbUtilities dbUtil = new DbUtilities(newWordsFullDataSet); //constructor for DbUtilities, takes in dataset as parameter. //Dataset out of scope in class variables. newSearch = dbUtil.SearchWithDb(searchTerms); //sets newSearch variable to return from SearchWithDb(), (terms and their synonyms) } var watch = System.Diagnostics.Stopwatch.StartNew();//starts a new instance of stop watch if (InvertedIndex.invertedIndex.Count == 0) //Builds inverted index if it yet to be built { index.BuildInvertedIndex(folderPath);//builds inverted Index } //Searches files and folders, reads contents, then fires the frequency methods. if (IncludeSynonyms.Checked) { Search.IndexedFileMatchTermDb(newSearch); } else { Search.IndexedFileMatchTerm(searchTerms); } watch.Stop(); //stops stop watch. long time = watch.ElapsedMilliseconds; //gets the time in milliseconds SearchTime.Text = time.ToString() + "ms"; //outputs time to form. AverageTime.Text = Average(time).ToString() + "ms"; //outputs average time to form. FileToForm(); //populates the listbox, number of files found and frequency textboxes } } }
/* * Takes input of file path and search terms. * Splits search terms into an array, and if include * synonyms is checked, fires method for setting * terms and synonyms (newSearch varible). * Calls SearchDirectory, runs timer while that is running, * and outputs time taken to form. * Fires the method to populate form with returned * data. * @param object sender, EventArgs e */ private void Searchbut_Click(object sender, EventArgs e) { Boolean useDatabase = false; //to handle include synonym checked/not checked. if (SelectFolder.Text == "") //error handling for no file path selected { MessageBox.Show("Please select a file and try again"); } if (SearchTerms.Text == "")//error handling for no search terms entered. { MessageBox.Show("Please a enter a search term, and try again"); } FilePathOutput.Items.Clear(); //clears list box. if (SearchTerms.Text != "" && SelectFolder.Text != "") //fires if there is a filepath and search term entered. { numSearch = numSearch + 1; //adds one to variable holding number of searches. Used for average time. searchTerms = SearchTerms.Text.Split(',', ' '); //splits the search terms at space or comma for (int i = 0; i < searchTerms.Length; i++) { searchTerms[i] = searchTerms[i].ToLower();//sets all entered search terms to lower case, to match the database. } if (IncludeSynonyms.Checked) { DbUtilities dbUtil = new DbUtilities(newWordsFullDataSet); //constructor for DbUtilities, takes in dataset as parameter. //Dataset out of scope in class variables. useDatabase = true; newSearch = dbUtil.SearchWithDb(searchTerms); //sets newSearch variable to return from SearchWithDb(), (terms and their synonyms) //database based as a parameter so SearchWithDb can access it } var watch = System.Diagnostics.Stopwatch.StartNew();//starts a new instance of stop watch fileUtil.SearchDir(folderPath, useDatabase, searchTerms, newSearch); //Searches files and folders, reads contents, then fires the search methods and frequency methods. watch.Stop(); //stops stop watch. long time = watch.ElapsedMilliseconds; //gets the time in milliseconds SearchTime.Text = time.ToString() + "ms"; //outputs time to form. AverageTime.Text = Average(time).ToString() + "ms"; //outputs average time to form. fileToForm(useDatabase); //populates the listbox, number of files found and frequency textboxes } }