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

            using (var searcher = _searcherFactory.Create()) {
                var version = _context.Entity.GetVersionField();

                _context.Debug(() => $"Detecting max input version: {_context.Connection.Folder}:{version.Name}.");

                var hits = searcher.Search(new MatchAllDocsQuery(), null, 1,
                                           new Sort(new SortField(version.Name, LuceneConversion.TypeSort(version.Type), true))
                                           );

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

            _context.Debug(() => "Did not find max input version");
            return(null);
        }
        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);
        }
        public int GetMaxTflKey()
        {
            var tflBatchId = _context.Entity.TflBatchId();
            var tflKey     = _context.Entity.TflKey();
            var keyHits    = _searcher.Search(new MatchAllDocsQuery(), null, 1,
                                              new Sort(new SortField(tflKey.Alias, LuceneConversion.TypeSort(tflKey.Type), true))
                                              );

            return(keyHits.TotalHits > 0 ? Convert.ToInt32(_searcher.Doc(keyHits.ScoreDocs[0].Doc).Get(tflKey.Alias)) : 0);
        }
Example #4
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);
                        }
                    }
                }
            }
        }
        public static AbstractField CreateField(FieldSearchType field, object value)
        {
            var           s = field.SearchType.Store ? LuceneField.Store.YES : LuceneField.Store.NO;
            AbstractField abstractField;

            switch (field.Field.Type)
            {
            case "byte":
                abstractField = new NumericField(field.Alias, s, field.SearchType.Index).SetIntValue(Convert.ToInt32(value));
                break;

            case "short":
            case "int16":
                abstractField = new NumericField(field.Alias, s, field.SearchType.Index).SetIntValue(Convert.ToInt32(value));
                break;

            case "int":
            case "int32":
                abstractField = new NumericField(field.Alias, s, field.SearchType.Index).SetIntValue((int)value);
                break;

            case "int64":
            case "long":
                abstractField = new NumericField(field.Alias, s, field.SearchType.Index).SetLongValue((long)value);
                break;

            case "double":
                abstractField = new NumericField(field.Alias, s, field.SearchType.Index).SetDoubleValue((double)value);
                break;

            case "decimal":
                abstractField = new LuceneField(field.Alias, ((decimal)value).ToString(LuceneConversion.CalculateDecimalFormat(field.Field.Precision, field.Field.Scale)), s, field.SearchType.Index ? LuceneField.Index.NOT_ANALYZED_NO_NORMS : LuceneField.Index.NO, LuceneField.TermVector.NO);
                break;

            case "float":
            case "single":
                abstractField = new NumericField(field.Alias, s, field.SearchType.Index).SetFloatValue((float)value);
                break;

            case "bool":
            case "boolean":
                abstractField = new LuceneField(field.Alias, (bool)value ? "1" : "0", s, LuceneField.Index.NOT_ANALYZED_NO_NORMS);
                break;

            case "datetime":
                abstractField = new LuceneField(field.Alias, DateTools.DateToString((DateTime)value, DateTools.Resolution.MILLISECOND), s, field.SearchType.Index ? LuceneField.Index.NOT_ANALYZED_NO_NORMS : LuceneField.Index.NO, LuceneField.TermVector.NO);
                break;

            case "rowversion":
            case "byte[]":
                abstractField = field.SearchType.Index ?
                                new LuceneField(field.Alias, Utility.BytesToHexString((byte[])value), s, LuceneField.Index.NOT_ANALYZED_NO_NORMS) :
                                new LuceneField(field.Alias, (byte[])value, s);
                break;

            case "string":
                var iString = field.SearchType.Index ? (
                    field.SearchType.Analyzer.Equals("keyword") ?
                    (field.SearchType.Norms ? LuceneField.Index.NOT_ANALYZED : LuceneField.Index.NOT_ANALYZED_NO_NORMS) :
                    (field.SearchType.Norms ? LuceneField.Index.ANALYZED : LuceneField.Index.ANALYZED_NO_NORMS)
                    ) :
                              LuceneField.Index.NO;

                abstractField = new LuceneField(field.Alias, value.ToString(), s, iString);
                break;

            default:
                var i = field.SearchType.Index ?
                        (field.SearchType.Norms ? LuceneField.Index.NOT_ANALYZED : LuceneField.Index.NOT_ANALYZED_NO_NORMS) :
                        LuceneField.Index.NO;

                abstractField = new LuceneField(field.Alias, value.ToString(), s, i);
                break;
            }
            return(abstractField);
        }