private void LoadCache_Click(object sender, RoutedEventArgs e) { //open new file OpenFileDialog dlg = new OpenFileDialog(); dlg.Filter = "Cache File|*.chex"; dlg.Title = "Open a cache File"; dlg.ShowDialog(); if (dlg.FileName != "") // If the file name is not an empty string, open it. { if (ind == null) //if its not after a full run { pathclose = @".\"; ind = new Indexer(pathclose, isStem); } using (FileStream fs = new FileStream(dlg.FileName, FileMode.Open)) { IFormatter bf = new BinaryFormatter(); ind.cache = (Dictionary <string, List <PostingInfo> >)bf.Deserialize(fs);//read object } ind.writeTextChache(); showcatch.IsEnabled = true; //notify when finished System.Windows.Forms.MessageBox.Show("Cache Loaded!", "Done!", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
//Load all files of part 2-corpus, stop words, cache, dictionary ,posting and rank private void Load2_click(object sender, RoutedEventArgs e) { //Folder Chooser var dlg = new FolderBrowserDialog(); System.Windows.Forms.DialogResult result = dlg.ShowDialog(this.GetIWin32Window()); //change the source path if (dlg.SelectedPath != "") { pathopen = dlg.SelectedPath; pathclose = dlg.SelectedPath; //init all the first part objects ind = new Indexer(pathclose, isStem); p = new Parser(pathopen + @"\stop_words.txt", isStem); r = new ReadFile(pathopen + @"\corpus\"); string dic; string cache; if (isStem)//check if stem { dic = pathclose + @"\CacheDic\dicStem.dicx"; cache = pathclose + @"\CacheDic\cacheStem.chex"; } else { dic = pathclose + @"\CacheDic\dic.dicx"; cache = pathclose + @"\CacheDic\cache.chex"; } try { //load dic using (FileStream fs = new FileStream(dic, FileMode.Open)) { IFormatter bf = new BinaryFormatter(); ind.dic = (Dictionary <string, DicRecord>)bf.Deserialize(fs);//read object } //load cache using (FileStream fs = new FileStream(cache, FileMode.Open)) { IFormatter bf = new BinaryFormatter(); ind.cache = (Dictionary <string, List <PostingInfo> >)bf.Deserialize(fs);//read object } } catch (IOException) { //cant find load and cache files in currect folder System.Windows.Forms.MessageBox.Show("Files Missing, can't Load", "ERROR!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //for vieiwing ind.writeTextChache(); showcatch.IsEnabled = true; ind.writeTextDic(); showDic.IsEnabled = true; //new ranker and load the dictionaries of the class if the file exists in the selected folder rank = new Ranker(pathclose, p, r, ind, isStem); searcher = new Searcher(p, ind, rank, pathopen); //open the run btn runQuery.IsEnabled = true; //notify when finished System.Windows.Forms.MessageBox.Show("Ready To search!!", "Done!", MessageBoxButtons.OK, MessageBoxIcon.Information); } }