private void LoadIndex(string dir, ulong collection) { var timer = new Stopwatch(); var batchTimer = new Stopwatch(); timer.Start(); var files = Directory.GetFiles(dir, "*.docs"); _log.Log(string.Format("index scan found {0} document files", files.Length)); foreach (var docFileName in files) { var name = Path.GetFileNameWithoutExtension(docFileName) .Split(".", StringSplitOptions.RemoveEmptyEntries); var collectionId = ulong.Parse(name[0]); if (collectionId == collection) { using (var readSession = new DocumentReadSession(collectionId, _sessionFactory)) { var docs = readSession.ReadDocs(); var job = new IndexJob(collectionId, docs); using (var writeSession = _sessionFactory.CreateWriteSession(collectionId)) { writeSession.WriteToIndex(job); } _log.Log(string.Format("loaded batch into {0} in {1}", collectionId, batchTimer.Elapsed)); } break; } } _log.Log(string.Format("loaded {0} indexes in {1}", files.Length, timer.Elapsed)); }
private static void Reindex(string dir, int batchSize) { var timer = new Stopwatch(); var batchTimer = new Stopwatch(); timer.Start(); var files = Directory.GetFiles(dir, "*.docs"); Console.WriteLine("re-indexing process found {0} document files", files.Length); foreach (var docFileName in files) { var name = Path.GetFileNameWithoutExtension(docFileName) .Split(".", StringSplitOptions.RemoveEmptyEntries); var collectionId = ulong.Parse(name[0]); using (var readSession = new DocumentReadSession(collectionId, new LocalStorageSessionFactory(dir, new LatinTokenizer()))) { foreach (var batch in readSession.ReadDocs().Batch(batchSize)) { batchTimer.Restart(); using (var writeSession = new LocalStorageSessionFactory(dir, new LatinTokenizer()).CreateWriteSession(collectionId)) { var job = new IndexJob(collectionId, batch); writeSession.WriteToIndex(job); } Console.WriteLine("wrote batch to {0} in {1}", collectionId, batchTimer.Elapsed); } } } Console.WriteLine("rebuilt {0} indexes in {1}", files.Length, timer.Elapsed); }