Exemple #1
0
        /// <summary>
        /// gets the document that contain the words in the query
        /// </summary>
        /// <param name="querywords">The querywords.</param>
        /// <param name="typesPossible">The types of document possible.</param>
        /// <returns></returns>
        private static Dictionary <Document, Dictionary <string, List <int> > > DocsFound(List <String> querywords, HashSet <string> typesPossible)
        {
            var found = new Dictionary <Document, Dictionary <string, List <int> > >();
            Dictionary <string, Dictionary <Document, List <int> > > available = new Dictionary <string, Dictionary <Document, List <int> > >();
            HashSet <Document> availableDocs = new HashSet <Document>(new DocumentComparer());
            String             QueryToTrie   = "";

            foreach (string word in querywords)
            {
                QueryToTrie += word + " ";
                if (!available.ContainsKey(word))
                {
                    Dictionary <Document, List <int> > thisWords = invt.AllDocumentsPositionsContainingWord(word);

                    available.Add(word, thisWords);
                    availableDocs.UnionWith(thisWords.Keys);
                }
            }

            foreach (Document x in availableDocs)
            {
                if (typesPossible.Contains(x.Type) && x.Exists)
                {
                    Dictionary <string, List <int> > wordDict = new Dictionary <string, List <int> >();
                    foreach (string word in querywords)
                    {
                        if (available[word].ContainsKey(x))
                        {
                            if (!wordDict.ContainsKey(word))
                            {
                                wordDict.Add(word, available[word][x]);
                            }
                        }
                        else
                        {
                            if (!wordDict.ContainsKey(word))
                            {
                                wordDict.Add(word, new List <int>());
                            }
                        }
                    }
                    found.Add(x, wordDict);
                }
            }
            return(found);
        }