public void select_documents() { string qq = @"select DOCID,frequancy,positions from Inverted_INDEX where stemm=@w;"; term = new word_and_docID(); for (int word = 1; word <= query_without_stopwords.Count; word++) { cmd = new SqlCommand(qq, con); cmd.Parameters.AddWithValue("@w", query_without_stopwords[word - 1]); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { term.word_number = word; term.document_ID = (Decimal)reader[0]; term.frequency = (Decimal)reader[1]; term.positions = reader[2].ToString(); all_documents.Add(term); } reader.Close(); MessageBox.Show(query_without_stopwords[word - 1].ToString()); } }
public void find_common_in_exact_search() { term = new word_and_docID(); word_and_docID term2 = new word_and_docID(); retreival_documents retreival_struct = new retreival_documents(); retreival_documents common = new retreival_documents(); string[] poss1, poss2; int score1; int score_sum; for (int i = 0; i < all_documents.Count - 1; i++) { score_sum = 1; term = all_documents[i]; for (int word_pos = 1; word_pos < query_without_stopwords.Count; word_pos++) { if (term.word_number == word_pos) { score1 = 1000000; for (int j = 0; j < all_documents.Count; j++) { term2 = all_documents[j]; if ((term2.word_number == word_pos + 1) && (term.document_ID == term2.document_ID)) { poss1 = term.positions.Split(','); poss2 = term2.positions.Split(','); for (int t1 = 0; t1 < poss2.Length; t1++) { for (int t2 = 0; t2 < poss1.Length; t2++) { int sc = (Convert.ToInt32(poss2[t1]) - Convert.ToInt32(poss1[t2])); if ((sc > 0) && (sc < score1)) { score1 = sc; } else { if (score1 != 1000000) { common.score = score1; common.docID = term.document_ID; if ((common_documents.Count < 20) && (!common_documents.Contains(common))) { common_documents.Add(common); } } } } } } } if (score1 != 1) { score_sum = 0; } } } if (score_sum == 1) { retreival_struct.score = score_sum; retreival_struct.docID = term.document_ID; retreival_struct.freq = term.frequency; if (!retrieval_exactsearch.Contains(retreival_struct)) { retrieval_exactsearch.Add(retreival_struct); } } } retrieval_exactsearch = retrieval_exactsearch.OrderByDescending(x => x.freq).ToList(); MessageBox.Show(retrieval_exactsearch.Count.ToString()); }