public override void WriteEndVersion(Process process, AbstractConnection input, Entity entity, bool force = false) { if (entity.Updates + entity.Inserts <= 0 && !force) { return; } var versionType = entity.Version == null ? "string" : entity.Version.SimpleType; var end = entity.End ?? new DefaultFactory(Logger).Convert(entity.End, versionType); using (var dir = LuceneDirectoryFactory.Create(this, TflBatchEntity(entity.ProcessName))) { using (var writer = new IndexWriter(dir, new KeywordAnalyzer(), IndexWriter.MaxFieldLength.UNLIMITED)) { var doc = new Document(); doc.fields.Add(new NumericField("id", Libs.Lucene.Net.Document.Field.Store.YES, true).SetIntValue(entity.TflBatchId)); doc.fields.Add(new Libs.Lucene.Net.Document.Field("process", entity.ProcessName, Libs.Lucene.Net.Document.Field.Store.YES, Libs.Lucene.Net.Document.Field.Index.NOT_ANALYZED_NO_NORMS)); doc.fields.Add(new Libs.Lucene.Net.Document.Field("connection", input.Name, Libs.Lucene.Net.Document.Field.Store.YES, Libs.Lucene.Net.Document.Field.Index.NOT_ANALYZED_NO_NORMS)); doc.fields.Add(new Libs.Lucene.Net.Document.Field("entity", entity.Alias, Libs.Lucene.Net.Document.Field.Store.YES, Libs.Lucene.Net.Document.Field.Index.NOT_ANALYZED_NO_NORMS)); doc.fields.Add(new NumericField("updates", Libs.Lucene.Net.Document.Field.Store.YES, true).SetLongValue(entity.Updates)); doc.fields.Add(new NumericField("inserts", Libs.Lucene.Net.Document.Field.Store.YES, true).SetLongValue(entity.Inserts)); doc.fields.Add(new NumericField("deletes", Libs.Lucene.Net.Document.Field.Store.YES, true).SetLongValue(entity.Deletes)); doc.fields.Add(LuceneWriter.CreateField("version", versionType, new SearchType { Analyzer = "keyword" }, end)); doc.fields.Add(new Libs.Lucene.Net.Document.Field("version_type", versionType, Libs.Lucene.Net.Document.Field.Store.YES, Libs.Lucene.Net.Document.Field.Index.NOT_ANALYZED_NO_NORMS)); doc.fields.Add(new NumericField("tflupdate", Libs.Lucene.Net.Document.Field.Store.YES, true).SetLongValue(DateTime.UtcNow.Ticks)); writer.AddDocument(doc); writer.Commit(); writer.Optimize(); } } }
public bool Check(AbstractConnection connection) { var hashCode = connection.Folder.GetHashCode(); if (Checks.ContainsKey(hashCode)) { return(Checks[hashCode]); } try { using (var indexDirectory = LuceneDirectoryFactory.Create(connection, connection.TflBatchEntity(_processName))) { using (var reader = IndexReader.Open(indexDirectory, true)) { connection.Logger.Debug("Successfully connected to lucene index in {0}.", connection.Folder); Checks[hashCode] = true; return(true); } } } catch (Exception ex) { _logger.Warn("Failed to connect to a lucene index in {0}.", connection.Folder); _logger.Debug(ex.Message); var exists = new DirectoryInfo(connection.Folder).Exists; Checks[hashCode] = exists; return(exists); } }
public bool RecordsExist(AbstractConnection connection, Entity entity) { var checker = new LuceneConnectionChecker(entity.ProcessName, connection.Logger); if (!checker.Check(connection)) { return(false); } var directoryInfo = new DirectoryInfo(LuceneDirectoryFactory.Path(connection, entity)); if (!directoryInfo.Exists) { return(false); } if (directoryInfo.GetFiles().Length == 0) { return(false); } using (var indexDirectory = LuceneDirectoryFactory.Create(connection, entity)) { using (var reader = IndexReader.Open(indexDirectory, true)) { var count = reader.NumDocs(); return(count > 0); } } }
public void Drop(AbstractConnection connection, Entity entity) { if (!EntityExists.Exists(connection, entity)) { return; } new DirectoryInfo(LuceneDirectoryFactory.Path(connection, entity)).Delete(true); }
public bool Exists(AbstractConnection connection, Entity entity) { if (!new DirectoryInfo(LuceneDirectoryFactory.Path(connection, entity)).Exists) { return(false); } using (var dir = LuceneDirectoryFactory.Create(connection, entity)) { return(dir.ListAll().Length > 0); } }
public static IndexWriter Create(AbstractConnection connection, Entity entity) { var dir = LuceneDirectoryFactory.Create(connection, entity); Analyzer defaultAnalyzer = new KeywordAnalyzer(); var analyzer = new PerFieldAnalyzerWrapper(defaultAnalyzer); foreach (var field in GetFields(entity, connection.Version, connection.Logger)) { analyzer.AddAnalyzer(field.Key, field.Value); } return(new IndexWriter(dir, analyzer, IndexWriter.MaxFieldLength.UNLIMITED)); }
public static IndexWriter Create(AbstractConnection connection, Process process, Entity entity) { using (var dir = LuceneDirectoryFactory.Create(connection, entity)) { Analyzer defaultAnalyzer = new KeywordAnalyzer(); if (process.SearchTypes.ContainsKey("default")) { defaultAnalyzer = LuceneAnalyzerFactory.Create(process.SearchTypes["default"].Analyzer, connection.Version); } var analyzer = new PerFieldAnalyzerWrapper(defaultAnalyzer); foreach (var field in GetFields(entity, connection.Version, connection.Logger)) { analyzer.AddAnalyzer(field.Key, field.Value); } return(new IndexWriter(dir, analyzer, IndexWriter.MaxFieldLength.UNLIMITED)); } }
public static IndexReader Create(AbstractConnection connection, Entity entity, bool readOnly) { return(IndexReader.Open(LuceneDirectoryFactory.Create(connection, entity), readOnly)); }