public object GetMaxVersion()
        {
            if (string.IsNullOrEmpty(_context.Entity.Version))
            {
                return(null);
            }

            var version = _context.Entity.GetVersionField();

            _context.Debug(() => $"Detecting max output version: {_context.Connection.Folder}.{_context.Entity.Alias}.{version.Alias}.");

            var tflDeleted = _context.Entity.TflDeleted();
            var sort       = new Sort(new SortField(version.Alias, LuceneConversion.TypeSort(version.Type), true));
            var hits       = _searcher.Search(LuceneConversion.TypeSearch(tflDeleted, tflDeleted.Alias, false), null, 1, sort);

            if (hits.TotalHits > 0)
            {
                var doc   = _searcher.Doc(hits.ScoreDocs[0].Doc);
                var value = doc.Get(version.Alias);
                _context.Debug(() => $"Found value: {value}");
                return(version.Convert(value));
            }

            _context.Debug(() => "Did not find max output version");
            return(null);
        }
Пример #2
0
        public IEnumerable <IRow> Read()
        {
            using (var reader = _readerFactory.Create()) {
                var numDocs  = reader.NumDocs();
                var selector = new MapFieldSelector(_fields.Select(f => f.Name).ToArray());

                using (var searcher = _searcherFactory.Create()) {
                    // read from input?  consider filters, and field names
                    if (_readFrom == ReadFrom.Input)
                    {
                        if (_context.Entity.Filter.Any())
                        {
                            var queryFields = _context.Entity.Filter.Select(f => f.Field).ToArray();
                            var query       = string.Join(" ", _context.Entity.Filter.Select(f => "(" + (string.IsNullOrEmpty(f.Expression) ? f.Field + ":" + f.Value : f.Expression) + ") " + f.Continuation.ToUpper()));
                            query = query.Remove(query.Length - 3);
                            var topFieldCollector = TopFieldCollector.Create(Sort.INDEXORDER, numDocs, false, false, false, false);

                            searcher.Search(new MultiFieldQueryParser(V, queryFields, _analyzer).Parse(query), topFieldCollector);

                            var topDocs = topFieldCollector.TopDocs();

                            if (topDocs == null)
                            {
                                yield break;
                            }

                            for (var i = 0; i < topDocs.TotalHits; i++)
                            {
                                var row = _rowFactory.Create();
                                var doc = searcher.Doc(i, selector);
                                foreach (var field in _fields)
                                {
                                    row[field] = field.Convert(doc.Get(field.Name));
                                }
                                yield return(row);
                            }
                        }
                        else
                        {
                            for (var i = 0; i < numDocs; i++)
                            {
                                if (reader.IsDeleted(i))
                                {
                                    continue;
                                }
                                var doc = reader.Document(i, selector);
                                var row = _rowFactory.Create();
                                foreach (var field in _fields)
                                {
                                    row[field] = field.Convert(doc.Get(field.Name));
                                }
                                yield return(row);
                            }
                        }
                    }
                    else // read from output? consider tfldeleted and field aliases

                    {
                        var tflDeleted = _context.Entity.TflDeleted();
                        var collector  = TopFieldCollector.Create(Sort.INDEXORDER, numDocs, false, false, false, false);
                        searcher.Search(LuceneConversion.TypeSearch(tflDeleted, tflDeleted.Alias, false), collector);

                        var topDocs = collector.TopDocs();

                        if (topDocs == null)
                        {
                            yield break;
                        }

                        for (var i = 0; i < topDocs.TotalHits; i++)
                        {
                            var row = _rowFactory.Create();
                            var doc = searcher.Doc(i, selector);
                            foreach (var field in _fields)
                            {
                                row[field] = field.Convert(doc.Get(field.Alias));
                            }
                            yield return(row);
                        }
                    }
                }
            }
        }