static void Main(string[] args) { try { // Step Two: Create TELog, and log the start of the application. // TELog.Log("Search application started"); // Step Four: Instantiate a Search Domain // SearchDomain sd = new SearchDomain("data"); TELog.Log("Indexed files:\n" + sd.ToString()); // Step Six: Single word search // // Step Seven: Multiple word search // } catch (Exception ex) { Console.WriteLine("General exception occurred:\n" + ex.StackTrace); } }
static void Main(string[] args) { try { // Step Two: Create TELog, and log the start of the application. // TELog.Log("Search application started"); // Step Four: Instantiate a Search Domain // SearchDomain domain = new SearchDomain("data"); TELog.Log(domain.ToString()); // Step Six: Single word search // SearchEngine searchEngine = new SearchEngine(domain); searchEngine.IndexFiles(); SearchAndPrintResults(searchEngine, "squirrel"); SearchAndPrintResults(searchEngine, "Larry"); // Step Seven: Multiple word search // SearchAndPrintResults(searchEngine, "telephone line"); } catch (Exception ex) { Console.WriteLine("General exception occurred:\n" + ex.StackTrace); } }
public void IndexFiles() { // Step Five: Index files for (int fileId = 0; fileId < domain.Files.Count; fileId++) { string fileName = domain.Files[fileId]; try { using (StreamReader reader = new StreamReader(fileName)) { while (!reader.EndOfStream) { string line = reader.ReadLine(); IndexWords(fileId, line); } } } catch (FileNotFoundException ex) { TELog.Log("Exception: File '" + fileName + "' is not found:\n" + ex.StackTrace); throw new SearchEngineException("Exception: File '" + fileName + "' is not found."); } catch (IOException ex) { TELog.Log("Exception: File '" + fileName + "' cannot be read:\n" + ex.StackTrace); throw new SearchEngineException("Exception: File '" + fileName + "' cannot be read."); } } TELog.Log("Indexed words:\n" + IndexedWordsToString()); }
public void IndexFiles() { // Step Five: Index files IList <string> domainFileList = domain.Files; for (int i = 0; i < domainFileList.Count; i++) { using (StreamReader streamReader = new StreamReader(domainFileList[i])) { string stringLine; while ((stringLine = streamReader.ReadLine()) != null) { IndexWords(i, stringLine); } } } TELog.Log(IndexedWordsToString()); }
public void IndexFiles() { // Step Five: Index files IList <string> files = domain.Files; for (int i = 0; i < files.Count; i++) { using (StreamReader sd = new StreamReader(files[i])) { while (!sd.EndOfStream) { string line = sd.ReadLine(); IndexWords(i, line); } } } TELog.Log(IndexedWordsToString()); }
static void Main(string[] args) { try { // Step Two: Create TELog, and log the start of the application. // TELog.Log("Search application started"); // Step Four: Instantiate a Search Domain // SearchDomain sd = new SearchDomain("data"); TELog.Log(sd.ToString()); // Step Six: Single word search // SearchEngine searchEngine = new SearchEngine(sd); searchEngine.IndexFiles(); Console.WriteLine("Single Word Search Result (squrrel):"); IList <string> filesWithSquirrel = searchEngine.Search("squirrel"); PrintListContents(filesWithSquirrel); // Step Seven: Multiple word search // Console.WriteLine("Multi Word Search Result (telephone line):"); IList <string> multiWordSearchResult = searchEngine.Search("telephone line"); PrintListContents(multiWordSearchResult); } catch (Exception ex) { Console.WriteLine("General exception occurred:\n" + ex.StackTrace); } }
static void Main(string[] args) { try { // Step Two: Create TELog, and log the start of the application. // TELog.Log("Search application started"); // Step Four: Instantiate a Search Domain // SearchDomain sd = new SearchDomain("data"); TELog.Log("Indexed files:\n" + sd.ToString()); //// Step Six: Single word search //// //SearchEngine se = new SearchEngine(sd); //se.IndexFiles(); //IList<string> foundInFiles = se.Search("squirrel"); //if (foundInFiles.Count > 0) //{ // foreach (string file in foundInFiles) // { // Console.WriteLine(file); // } //} //else //{ // Console.WriteLine("The search term does not appear in any of the indexed files."); //} //foundInFiles = se.Search("Larry"); //if (foundInFiles.Count > 0) //{ // foreach (string file in foundInFiles) // { // Console.WriteLine(file); // } //} //else //{ // Console.WriteLine("The search term does not appear in any of the indexed files."); //} // Step Seven: Multiple word search // SearchEngine se = new SearchEngine(sd); se.IndexFiles(); IList <string> foundInFiles = se.Search("telephone line"); if (foundInFiles.Count > 0) { foreach (string file in foundInFiles) { Console.WriteLine(file); } } else { Console.WriteLine("The search term does not appear in any of the indexed files."); } } catch (SearchDomainException ex) { TELog.Log("Search domain exception occurred:\n" + ex.StackTrace); } catch (Exception ex) { Console.WriteLine("General exception occurred:\n" + ex.StackTrace); } }