private long Truncate(string srcIxFileName) { Log.InfoFormat("truncating {0}", srcIxFileName); var srcIx = SegmentInfo.Load(srcIxFileName); var srcDataFileName = Path.Combine(_directory, srcIx.Version + ".rdb"); long version; using (var source = new FileStream(srcDataFileName, FileMode.Open)) using (var documentStream = new DocumentTableStream(source, srcIx)) { using (var upsert = new FullTextUpsertTransaction( _directory, _analyzer, srcIx.Compression, documentStream)) { version = upsert.Write(); } Log.InfoFormat("truncated ix {0}", version); } File.Delete(srcIxFileName); return(version); }
static void Rewrite(string[] args) { var take = int.MaxValue; var skip = 0; string pk = null; bool gzip = false; bool lz = false; string dir = null; if (Array.IndexOf(args, "--take") > 0) { take = int.Parse(args[Array.IndexOf(args, "--take") + 1]); } if (Array.IndexOf(args, "--skip") > 0) { skip = int.Parse(args[Array.IndexOf(args, "--skip") + 1]); } if (Array.IndexOf(args, "--pk") > 0) { pk = args[Array.IndexOf(args, "--pk") + 1]; } if (Array.IndexOf(args, "--gzip") > 0) { gzip = true; } if (Array.IndexOf(args, "--lz") > 0) { lz = true; } if (Array.IndexOf(args, "--dir") > 0) { dir = args[Array.IndexOf(args, "--dir") + 1]; } var compression = gzip ? Compression.GZip : lz ? Compression.Lz : Compression.NoCompression; var dataFileName = args[Array.IndexOf(args, "--file") + 1]; var ixFileName = Directory.GetFiles(Path.GetDirectoryName(dataFileName), "*.ix") .OrderBy(s => s).First(); var ix = SegmentInfo.Load(ixFileName); Console.WriteLine("rewriting..."); var writeTimer = new Stopwatch(); writeTimer.Start(); using (var stream = new FileStream(dataFileName, FileMode.Open)) using (var documents = new DocumentTableStream(stream, ix, skip, take)) using (var upsert = new FullTextUpsertTransaction(dir, new Analyzer(), compression, documents)) { upsert.Write(); } Console.WriteLine("write operation took {0}", writeTimer.Elapsed); }
static void Export(string[] args) { var take = int.MaxValue; var skip = 0; if (Array.IndexOf(args, "--take") > 0) { take = int.Parse(args[Array.IndexOf(args, "--take") + 1]); } if (Array.IndexOf(args, "--skip") > 0) { skip = int.Parse(args[Array.IndexOf(args, "--skip") + 1]); } var sourceFileName = args[Array.IndexOf(args, "--source-file") + 1]; var targetFileName = args[Array.IndexOf(args, "--target-file") + 1]; var dir = Path.GetDirectoryName(sourceFileName); var version = Path.GetFileNameWithoutExtension(sourceFileName); var ix = SegmentInfo.Load(Path.Combine(dir, version + ".ix")); Console.WriteLine("migrating..."); var writeTimer = new Stopwatch(); writeTimer.Start(); using (var sourceStream = new FileStream(sourceFileName, FileMode.Open)) using (var targetStream = new FileStream(targetFileName, FileMode.Create)) using (var jsonWriter = new StreamWriter(targetStream, Encoding.UTF8)) using (var documents = new DocumentTableStream(sourceStream, ix, skip, take)) { jsonWriter.WriteLine("["); foreach (var document in documents.ReadSource()) { var dic = document.Fields.ToDictionary(x => x.Key, y => y.Value.Value); var json = JsonConvert.SerializeObject(dic, Formatting.None); jsonWriter.WriteLine(json); } jsonWriter.Write("]"); } Console.WriteLine("write operation took {0}", writeTimer.Elapsed); }