public static void Syncronize(DirectoryInfo sessionDirectory, IDocumentFileNameProvider fileNameProvider) { using (Mutex) { using (var fsDirectory = FSDirectory.Open(fileNameProvider.GetLuceneDirectory())) { using (var writer = new IndexWriter(fsDirectory, Analyser, IndexWriter.MaxFieldLength.UNLIMITED)) { using (var readerDirectory = FSDirectory.Open(sessionDirectory)) { using (var reader = IndexReader.Open(readerDirectory, true)) { writer.AddIndexes(reader); } } } } } }
private void Initialize() { if (string.IsNullOrEmpty(DataLocation)) throw new ArgumentException("DataLocation cannot be empty"); if (string.IsNullOrEmpty(DatabaseName)) throw new ArgumentException("DatabaseName cannot be empty"); _fileNameProvider = new DocumentFileNameProvider(DataLocation, DatabaseName); if (!Directory.Exists(DataLocation)) throw new DirectoryNotFoundException(String.Format("The directory '{0}' doesn't exist", DataLocation)); var dataDirectory = new DirectoryInfo(DataLocation); string dbDir = dataDirectory.FullName + "\\" + DatabaseName; if (!Directory.Exists(dbDir)) { Directory.CreateDirectory(dbDir + "\\trx"); } var lucene = _fileNameProvider.GetLuceneRootDirectory(); if (!lucene.Exists) { lucene.Create(); } }