public List<DocumentResult> Search(string query) { Hashtable resultHash = new Hashtable(); List<DocumentResult> resultList = new List<DocumentResult>(); Query parsedQuery = new Query(query); List<Word> wordFound = FindWords(parsedQuery); //merging the list. foreach (Word item in wordFound) { List<WordOccurrenceNode> tempDocList = InvertedFileManager.Instance.GetWordOccurrencies(item); foreach (WordOccurrenceNode wordOccur in tempDocList) { if (!resultHash.ContainsKey(wordOccur.Doc.DocID)) { DocumentResult newDoc = new DocumentResult(wordOccur.Doc); newDoc.CalculateRank(wordOccur, parsedQuery); resultHash.Add(newDoc.DocID, newDoc); } else { DocumentResult newDoc = resultHash[wordOccur.Doc.DocID] as DocumentResult; newDoc.CalculateRank(wordOccur, parsedQuery); } } } //convert hasthtable to list foreach (DictionaryEntry entry in resultHash) { DocumentResult doc = entry.Value as DocumentResult; resultList.Add(doc); } //sort result list by QueryRank and return resultList.Sort((y, x) => x.QueryRank.CompareTo(y.QueryRank)); return resultList; }
public List<DocumentResult> Search(string query) { Hashtable resultHash = new Hashtable(); List<DocumentResult> resultList = new List<DocumentResult>(); Query parsedQuery = new Query(query); List<Word> wordFound = FindWords(parsedQuery); //merging the list. foreach (Word item in wordFound) { WordOccurrenceNode firstOcc = item.FirstOccurrence; //problem: the number of occurrences is wrong! The 'else' case, doesn't exist and because this, //the program don't count the occurrences of the second word. //when he merge, it discards the occurrences. if (!resultHash.ContainsKey(firstOcc.Doc.DocID)) { DocumentResult newDoc = new DocumentResult(firstOcc.Doc); newDoc.CalculateRank(firstOcc, parsedQuery); resultHash.Add(newDoc.DocID, newDoc); } else { DocumentResult newDoc = resultHash[firstOcc.Doc.DocID] as DocumentResult; newDoc.CalculateRank(firstOcc, parsedQuery); } WordOccurrenceNode tmp = firstOcc; while (tmp.HasNext()) { tmp = tmp.NextOccurrence; if (!resultHash.ContainsKey(tmp.Doc.DocID)) { DocumentResult newDoc = new DocumentResult(tmp.Doc); newDoc.CalculateRank(tmp, parsedQuery); resultHash.Add(newDoc.DocID, newDoc); } else { DocumentResult newDoc = resultHash[tmp.Doc.DocID] as DocumentResult; newDoc.CalculateRank(tmp, parsedQuery); } } } //convert hasthtable to list foreach (DictionaryEntry entry in resultHash) { DocumentResult doc = entry.Value as DocumentResult; resultList.Add(doc); } //sort result list by QueryRank and return resultList.Sort((y, x) => x.QueryRank.CompareTo(y.QueryRank)); return resultList; }