public bool AddDoc(String key, String stringToIndex, Dictionary <String, String> stringsToStore) { if (!docs.ContainsKey(key)) { String stringToIndexLowerCase = stringToIndex.ToLower(); #region Add Document to Document Dictionary Document doc = new Document(stringToIndexLowerCase, new Dictionary <string, string>(stringsToStore)); //int docPosition = docs.Count; docs.TryAdd(key, doc); #endregion #region Add Document terms to the index Dictionary <String, int> termFrequency = new Dictionary <string, int>(); // Contains all terms with their respective frequency. foreach (String str in stringToIndexLowerCase.Split(' ')) { // Splits input String that will be indexed. if (termFrequency.ContainsKey(str)) { // Checks if the Dictonary already contains given term termFrequency[str]++; // if so +1 } else { termFrequency.Add(str, 1); // else add term to Dictonary with count 1. } } foreach (KeyValuePair <String, int> term in termFrequency) { // Goes through all of the terms lex.AddPost(term.Key, key, term.Value); } #endregion return(true); } return(false); }