public void Lazy() { var dir = Setup.Dir + "\\lazy"; if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } var words = new LazyTrie(Path.Combine(dir, "abc123.tc")); words.Add("treaty"); words.Add("treating"); words.Add("tree"); words.Add("pre"); words.Add("prefix"); Assert.AreEqual(3, words.Prefixed("tre").Count()); Assert.AreEqual(1, words.Prefixed("tree").Count()); Assert.AreEqual(2, words.Prefixed("pre").Count()); Assert.AreEqual(1, words.Prefixed("pref").Count()); Assert.IsTrue(words.Similar("tre", 1).Contains("tree")); Assert.IsFalse(words.Similar("tre", 1).Contains("treat")); Assert.IsFalse(words.Similar("tre", 1).Contains("treaty")); Assert.IsFalse(words.Similar("tre", 1).Contains("treating")); Assert.IsTrue(words.Similar("tre", 1).Contains("pre")); using (var container = new TrieWriter("abc123")) { words.Save(container, dir); } var lz = new LazyTrie(Path.Combine(dir, "abc123.tc")); Assert.AreEqual(3, lz.Prefixed("tre").Count()); Assert.AreEqual(1, lz.Prefixed("tree").Count()); Assert.AreEqual(2, lz.Prefixed("pre").Count()); Assert.AreEqual(1, lz.Prefixed("pref").Count()); Assert.AreEqual(0, lz.Prefixed("cracker").Count()); Assert.IsTrue(lz.Similar("tre", 1).Contains("tree")); Assert.IsFalse(lz.Similar("tre", 1).Contains("treat")); Assert.IsFalse(lz.Similar("tre", 1).Contains("treaty")); Assert.IsFalse(lz.Similar("tre", 1).Contains("treating")); Assert.IsTrue(lz.Similar("tre", 1).Contains("pre")); }
public void Dispose() { foreach (var docId in _deletions) { DoRemove(docId); } Parallel.ForEach(_trieFiles, kvp => { var field = kvp.Key; var trie = kvp.Value; using (var container = new TrieWriter(field.ToTrieContainerId())) { trie.Save(container, _directory); } }); _docWorker.Dispose(); _postingsWorker.Dispose(); Parallel.ForEach(_postingsContainers.Values, container => { if (container.Count > 0) { container.Flush(_directory); container.Dispose(); } else { container.Dispose(); File.Delete(Path.Combine(_directory, container.Id + ".pc")); } }); Parallel.ForEach(_docContainers.Values, container => container.Dispose()); _ix.Save(Path.Combine(_directory, "1.ix")); var ixInfo = new IxInfo(); foreach (var field in _ix.Fields) { ixInfo.DocCount[field.Key] = field.Value.Count; } ixInfo.Save(Path.Combine(_directory, "0.ix")); }