private IndexResult AddtoIndex(int recnum, string text /*, bool optimizeIndexes*/) { _log("text size = " + text.Length); Dictionary <string, int> wordFrequences = GenerateWordFreq(text); _log("word count = " + wordFrequences.Count); var result = new IndexResult { DocNumber = recnum }; using (var bmp = CreateBitmapStream()) { foreach (string word in wordFrequences.Keys) { Cache cache; if (_index.TryGetValue(word, out cache)) { LoadCacheIfNotLoaded(cache, bmp); cache.SetBit(recnum, true); } else { cache = new Cache { isLoaded = true }; cache.SetBit(recnum, true); _index.Add(word, cache); } result.WordsAdded.Add(word, wordFrequences[word]); } } return(result); }
public IndexResult UpdateExistingIndex(int recnum, string text) { Log("UpdateExistingIndex started"); LogIndex(); Log(string.Format("text size = {0}", text.Length)); Dictionary <string, int> wordFrequencies = GenerateWordFreq(text); Log(string.Format("word count = {0}", wordFrequencies.Count)); var result = new IndexResult { DocNumber = recnum }; using (var bmp = CreateBitmapStream()) { foreach (KeyValuePair <string, Cache> vc in _index) { string indexedWord = vc.Key; Cache cache = vc.Value; LoadCacheIfNotLoaded(cache, bmp); bool isWordIndexed = cache.GetBitmap().Get(recnum); bool isWordInText = wordFrequencies.ContainsKey(indexedWord); if (isWordIndexed && isWordInText) { wordFrequencies.Remove(indexedWord); } else if (isWordIndexed) { result.WordsRemoved.Add(indexedWord); cache.SetBit(recnum, false); } else if (isWordInText) { result.WordsAdded.Add(indexedWord, wordFrequencies[indexedWord]); wordFrequencies.Remove(indexedWord); cache.SetBit(recnum, true); } } } foreach (var wordFrequency in wordFrequencies) { result.WordsAdded.Add(wordFrequency.Key, wordFrequency.Value); var cache = new Cache { isLoaded = true }; cache.SetBit(recnum, true); _index.Add(wordFrequency.Key, cache); } LogIndex(); Log("UpdateExistingIndex ended"); return(result); }