static void Merge(string[] args) { string dir = null; if (Array.IndexOf(args, "--dir") > 0) { dir = args[Array.IndexOf(args, "--dir") + 1]; } if (dir != null) { using (var merge = new MergeTransaction(dir)) { var result = merge.Commit(); if (result == -1) { Console.Write("nothing to merge or truncate in dir {0}", dir); } } } }
public void Can_truncate() { var dir = CreateDir(); var docs = new List <dynamic> { new { _id = "0", title = "Rambo First Blood" }, new { _id = "1", title = "the rain man" }, new { _id = "2", title = "the good, the bad and the ugly" } }.ToDocuments(primaryKeyFieldName: "_id"); var moreDocs = new List <dynamic> { new { _id = "3", title = "rambo 2" }, new { _id = "4", title = "rocky 2" }, new { _id = "5", title = "the raiders of the lost ark" }, }.ToDocuments(primaryKeyFieldName: "_id"); long indexName; long indexName2; using (var writer = new UpsertTransaction( dir, new Analyzer(), compression: Compression.NoCompression, documents: docs)) { indexName = writer.Write(); using (var writer2 = new UpsertTransaction( dir, new Analyzer(), compression: Compression.NoCompression, documents: moreDocs)) { indexName2 = writer2.Write(); } } using (var merge1 = new MergeTransaction(dir)) merge1.Commit(); using (var searcher = new Searcher(dir)) { var result = searcher.Search("title:rambo"); Assert.AreEqual(2, result.Total); Assert.AreEqual(2, result.Docs.Count); Assert.IsTrue(result.Docs.Any(d => d.Document.Fields["_id"].Value == "0")); Assert.IsTrue(result.Docs.Any(d => d.Document.Fields["_id"].Value == "3")); } using (var merge2 = new MergeTransaction(dir)) merge2.Commit(); using (var searcher = new Searcher(dir)) { var result = searcher.Search("title:rambo"); Assert.AreEqual(2, result.Total); Assert.AreEqual(2, result.Docs.Count); Assert.IsTrue(result.Docs.Any(d => d.Document.Fields["_id"].Value == "0")); Assert.IsTrue(result.Docs.Any(d => d.Document.Fields["_id"].Value == "3")); } using (var merge3 = new MergeTransaction(dir)) { var result = merge3.Commit(); Assert.AreEqual(-1, result); } using (var searcher = new Searcher(dir)) { var result = searcher.Search("title:rambo"); Assert.AreEqual(2, result.Total); Assert.AreEqual(2, result.Docs.Count); Assert.IsTrue(result.Docs.Any(d => d.Document.Fields["_id"].Value == "0")); Assert.IsTrue(result.Docs.Any(d => d.Document.Fields["_id"].Value == "3")); } }