Пример #1
0
        public override void LoadEndVersion(Entity entity)
        {
            using (var searcher = LuceneSearcherFactory.Create(this, entity)) {
                var query    = new MatchAllDocsQuery();
                var sortType = LuceneWriter.SortMap.ContainsKey(entity.Version.SimpleType) ? LuceneWriter.SortMap[entity.Version.SimpleType] : LuceneWriter.SortMap["*"];
                var sort     = new Sort(new SortField(entity.Version.Alias, sortType, true));
                var hits     = searcher.Search(query, null, 1, sort);

                entity.HasRows = hits.TotalHits > 0;

                if (!entity.HasRows)
                {
                    return;
                }

                var doc = searcher.Doc(0);
                entity.End = Common.GetObjectConversionMap()[entity.Version.SimpleType](doc.Get(entity.Version.Alias));
            }
        }
Пример #2
0
        public override void LoadBeginVersion(Entity entity)
        {
            using (var searcher = LuceneSearcherFactory.Create(this, TflBatchEntity(entity.ProcessName))) {
                var parser = new MultiFieldQueryParser(LuceneVersion(), new[] { "process", "entity" }, new KeywordAnalyzer());
                var query  = parser.Parse(string.Format("process:\"{0}\" AND entity:\"{1}\"", entity.ProcessName, entity.Alias));
                var sort   = new Sort(new SortField("id", SortField.INT, true));
                var hits   = searcher.Search(query, null, 1, sort);

                entity.HasRange = hits.TotalHits > 0;

                if (!entity.HasRange)
                {
                    return;
                }

                var doc  = searcher.Doc(0);
                var type = doc.GetField("version_type").StringValue;
                entity.Begin = Common.GetObjectConversionMap()[type](doc.GetField("version").StringValue);
            }
        }
Пример #3
0
        public override int NextBatchId(string processName)
        {
            if (!TflBatchRecordsExist(processName))
            {
                return(1);
            }
            using (var searcher = LuceneSearcherFactory.Create(this, TflBatchEntity(processName))) {
                var query = new TermQuery(new Term("process", processName));
                var sort  = new Sort(new SortField("id", SortField.INT, true));
                var hits  = searcher.Search(query, null, 1, sort);

                if (hits.TotalHits <= 0)
                {
                    return(1);
                }

                var doc = searcher.Doc(0);
                return(Convert.ToInt32(doc.GetField("id").StringValue) + 1);
            }
        }