/// <summary> /// perform Search /// </summary> /// <param name="query"></param> /// <param name="chosenLangs"></param> public void performSearch(string query, List <string /*lang*/> chosenLangs) { if (m_Dictionary == null) { ModelChanged("You should load or create an index first :("); return; } if (m_stemOn) { query = query.ToLower(); Stemmer stemmer = new Stemmer(); string[] splited = query.Split(' '); for (int i = 0; i < splited.Length; i++) { splited[i] = stemmer.stemTerm(splited[i]); } string stemmedQuery = ""; for (int i = 0; i < splited.Length - 1; i++) { stemmedQuery = splited[i] + " "; } stemmedQuery += splited[splited.Length - 1]; query = stemmedQuery; query = query.ToUpper(); } m_searcher.setSearcher(m_N, m_Dictionary, m_pathToPosting, m_docsLength, m_avdl, "stop_words.txt"); m_searchResults = m_searcher.ansForQuery(query, m_docLangDict, chosenLangs); m_searchResults.Add(query + "|" + m_queryID); m_queryID++; ModelChanged("searchResultsReady"); }
private void addToParsedList(string term) //adds to term to persed list stemmed or not according to flag stemOn { if (m_stemOn) { term = term.ToLower(); term = m_stemmer.stemTerm(term); term = term.ToUpper(); } m_parsedTermsOfDoc.Add(term); }
/// <summary> /// get File Quries /// </summary> /// <param name="pathToFileQ"></param> /// <returns></returns> private Dictionary <string, string> getFileQuries(string pathToFileQ) { Dictionary <string, string> quries = new Dictionary <string, string>(); StreamReader file = new StreamReader(pathToFileQ); string line; while ((line = file.ReadLine()) != null) { string[] splitedLine = line.Split(' '); string id = splitedLine[0]; string query = ""; for (int i = 1; i < splitedLine.Length; i++) { query = query + " " + splitedLine[i]; } if (query != null && query != "") { query = query.Substring(1); if (m_stemOn) { Stemmer stemmer = new Stemmer(); string[] splited = query.Split(' '); for (int i = 0; i < splited.Length; i++) { splited[i] = splited[i].ToLower(); splited[i] = stemmer.stemTerm(splited[i]); } string stemmedQuery = ""; for (int i = 0; i < splited.Length - 1; i++) { stemmedQuery = splited[i] + " "; } stemmedQuery += splited[splited.Length - 1]; query = stemmedQuery; } query = query.ToUpper(); quries.Add(id, query); } } return(quries); }