示例#1
0
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            if (!(value is TermQuery))
                throw new SerializeTypeException<TermQuery>();

            TermQuery query = value as TermQuery;

            Dictionary<string, object> fieldDict = new Dictionary<string, object>();
            if (query.Boost != QuerySerializer._BOOST_DEFAULT)
            {
                Dictionary<string, object> internalDict = new Dictionary<string, object>();
                internalDict.Add(_VALUE, query.Value);
                internalDict.AddObject(QuerySerializer._BOOST, query.Boost, QuerySerializer._BOOST_DEFAULT);
                internalDict.AddObject(QuerySerializer._QUERY_NAME, query.QueryName);
                fieldDict.Add(query.Field, internalDict);
            }
            else
            {
                fieldDict.Add(query.Field, query.Value);
            }

            Dictionary<string, object> queryDict = new Dictionary<string, object>();
            queryDict.Add(QueryTypeEnum.Term.ToString(), fieldDict);

            serializer.Serialize(writer, queryDict);
        }
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            if (!(value is SimpleQueryStringQuery))
                throw new SerializeTypeException<SimpleQueryStringQuery>();

            SimpleQueryStringQuery query = value as SimpleQueryStringQuery;
            
            Dictionary<string, object> fieldDict = new Dictionary<string, object>();
            fieldDict.AddObject(_FIELDS, query.Fields);
            fieldDict.Add(_QUERY, query.Query);
            fieldDict.AddObject(_ANALYZER, query.Analyzer);
            fieldDict.AddObject(_DEFAULT_OPERATOR, query.DefaultOperator.ToString(), _DEFAULT_OPERATOR_DEFAULT.ToString());
            if (query.ParsingFeatureFlags != null && query.ParsingFeatureFlags.Any(x => x != null))
            {
                string defaultValue = string.Join(_FLAG_DELIMITER, _FLAGS_DEFAULT.Select(x => x.ToString()));
                string flagsValue = string.Join(_FLAG_DELIMITER, query.ParsingFeatureFlags.Where(x => x != null).Select(x => x.ToString()));

                fieldDict.AddObject(_FLAGS, flagsValue, defaultValue);
            }

            fieldDict.AddObject(QuerySerializer._QUERY_NAME, query.QueryName);

            Dictionary<string, object> queryDict = new Dictionary<string,object>();
            queryDict.Add(QueryTypeEnum.SimpleQueryString.ToString(), fieldDict);

            serializer.Serialize(writer, queryDict);
        }
示例#3
0
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            if (!(value is RangeAggregate))
                throw new SerializeTypeException<RangeAggregate>();

            RangeAggregate agg = value as RangeAggregate;

            Dictionary<string, object> fieldDict = new Dictionary<string, object>();
            fieldDict.AddObject(_FIELD, agg.Field);
            agg.Script.Serialize(fieldDict);
            fieldDict.AddObject(_KEYED, agg.AreRangesKeyed, _KEYED_DEFAULT);
            fieldDict.AddObject(_RANGES, agg.Ranges.Select(x => SerializeRangeBucket(x)));
            Dictionary<string, object> aggDict = new Dictionary<string, object>();
            aggDict.Add(AggregationTypeEnum.Range.ToString(), fieldDict);

            Dictionary<string, object> subAggsDict = agg.SerializeSubAggregations();
            if (subAggsDict != null)
            {
                aggDict.Add(BucketAggregationBase._SUB_AGGREGATIONS, subAggsDict);
            }

            Dictionary<string, object> aggNameDict = new Dictionary<string, object>();
            aggNameDict.Add(agg.Name, aggDict);

            serializer.Serialize(writer, aggNameDict);
        }
示例#4
0
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            if (!(value is FuzzyQueryBase))
                throw new SerializeTypeException<FuzzyQueryBase>();

            FuzzyQueryBase query = value as FuzzyQueryBase;
            Dictionary<string, object> fieldDict = new Dictionary<string, object>();

            if (query.Boost == QuerySerializer._BOOST_DEFAULT && query.Fuzziness == null && query.MaximumExpansions == default(int) && query.PrefixLength == default(int))
            {
                fieldDict.Add(query.Field, query.Value);
            }
            else
            {
                Dictionary<string, object> detailDict = new Dictionary<string, object>();
                detailDict.Add(_VALUE, query.Value);
                detailDict.AddObject(QuerySerializer._BOOST, query.Boost, QuerySerializer._BOOST_DEFAULT);
                detailDict.AddObject(_FUZZINESS, query.Fuzziness);
                detailDict.AddObject(_PREFIX_LENGTH, query.PrefixLength, _PREFIX_LENGTH_DEFAULT);
                detailDict.AddObject(_MAXIMUM_EXPANSIONS, query.MaximumExpansions, _MAXIMUM_EXPANSIONS_DEFAULT);
                
                fieldDict.Add(query.Field, detailDict);
            }

            Dictionary<string, object> fuzzyDict = new Dictionary<string, object>();
            fuzzyDict.Add(QueryTypeEnum.Fuzzy.ToString(), fieldDict);

            serializer.Serialize(writer, fuzzyDict);
        }
示例#5
0
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            if (!(value is RangeFilterBase))
                throw new SerializeTypeException<RangeFilterBase>();

            RangeFilterBase filter = value as RangeFilterBase;
            Dictionary<string, object> fieldDict = new Dictionary<string, object>();

            fieldDict.AddObject(_GREATER_THAN, filter.GreaterThan);
            fieldDict.AddObject(_LESS_THAN, filter.LessThan);
            fieldDict.AddObject(_GREATER_THAN_OR_EQUAL_TO, filter.GreaterThanOrEqualTo);
            fieldDict.AddObject(_LESS_THAN_OR_EQUAL_TO, filter.LessThanOrEqualTo);

            Dictionary<string, object> internalDict = new Dictionary<string, object>();
            internalDict.Add(filter.Field, fieldDict);

            if(filter.ExecutionType != null)
                internalDict.AddObject(_EXECUTION, filter.ExecutionType.ToString());

            if (filter.ExecutionType != null && filter.ExecutionType == ExecutionTypeEnum.Index)
                FilterSerializer.SerializeBaseValues(filter, _INDEX_EXECUTION_CACHE_DEFAULT, internalDict);
            else
                FilterSerializer.SerializeBaseValues(filter, _CACHE_DEFAULT, fieldDict);

            Dictionary<string, object> queryDict = new Dictionary<string, object>();
            queryDict.Add(FilterTypeEnum.Range.ToString(), internalDict);

            serializer.Serialize(writer, queryDict);
        }
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            if (!(value is HistogramAggregate))
                throw new SerializeTypeException<HistogramAggregate>();

            HistogramAggregate agg = value as HistogramAggregate;

            Dictionary<string, object> fieldDict = new Dictionary<string, object>();
            fieldDict.AddObject(_FIELD, agg.Field);
            agg.Script.Serialize(fieldDict);
            fieldDict.AddObject(_INTERVAL, agg.Interval);
            fieldDict.AddObject(_MINIMUM_DOCUMENT_COUNT, agg.MinimumDocumentCount, _MINIMUM_DOCUMENT_COUNT_DEFAULT);
            fieldDict.AddObject(_KEYED, agg.AreBucketsKeyed, _KEYED_DEFAULT);

            if (!string.IsNullOrWhiteSpace(agg.SortValue))
            {
                Dictionary<string, object> orderDict = new Dictionary<string, object>();
                orderDict.Add(agg.SortValue, agg.SortOrder.ToString());
                fieldDict.Add(_ORDER, orderDict);
            }

            Dictionary<string, object> aggDict = new Dictionary<string, object>();
            aggDict.Add(AggregationTypeEnum.Histogram.ToString(), fieldDict);

            Dictionary<string, object> subAggsDict = agg.SerializeSubAggregations();
            if (subAggsDict != null)
            {
                aggDict.Add(BucketAggregationBase._SUB_AGGREGATIONS, subAggsDict);
            }

            Dictionary<string, object> aggNameDict = new Dictionary<string, object>();
            aggNameDict.Add(agg.Name, aggDict);

            serializer.Serialize(writer, aggNameDict);
        }
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            if (!(value is CompletionSuggester))
                throw new SerializeTypeException<CompletionSuggester>();

            CompletionSuggester suggestor = value as CompletionSuggester;

            Dictionary<string, object> compDict = new Dictionary<string, object>();
            compDict.AddObject(SuggestSerializer._FIELD, suggestor.Field);
            compDict.AddObject(SuggestSerializer._SIZE, suggestor.Size, SuggestSerializer._SIZE_DEFAULT);
            if (suggestor.Fuzzy != null)
            {
                Dictionary<string, object> fuzzyDict = new Dictionary<string, object>();
                fuzzyDict.AddObject(_FUZZINESS, suggestor.Fuzzy.Fuzziness, _FUZZINESS_DEFAULT);
                fuzzyDict.AddObject(_IS_UNICODE_AWARE, suggestor.Fuzzy.IsUnicodeAware, _IS_UNICODE_AWARE_DEFAULT);
                fuzzyDict.AddObject(_MINIMUM_LENGTH, suggestor.Fuzzy.MinimumLength, _MINIMUM_LENGTH_DEFAULT);
                fuzzyDict.AddObject(_PREFIX_LENGTH, suggestor.Fuzzy.PrefixLength, _PREFIX_LENGTH_DEFAULT);
                fuzzyDict.AddObject(_TRANSPOSITIONS, suggestor.Fuzzy.Transpositions, _TRANSPOSITIONS_DEFAULT);

                compDict.Add(_FUZZY, fuzzyDict);
            }

            Dictionary<string, object> internalDict = new Dictionary<string, object>();
            internalDict.AddObject(SuggestSerializer._TEXT, suggestor.Text);
            internalDict.Add(SuggestTypeEnum.Completion.ToString(), compDict);

            Dictionary<string, object> suggestDict = new Dictionary<string, object>();
            suggestDict.Add(suggestor.SuggestName, internalDict);

            serializer.Serialize(writer, suggestDict);
        }
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            if (!(value is CommonGramsTokenFilter))
                throw new SerializeTypeException<CommonGramsTokenFilter>();

            CommonGramsTokenFilter filter = value as CommonGramsTokenFilter;
            Dictionary<string, object> fieldDict = new Dictionary<string, object>();
            TokenFilterBase.Serialize(filter, fieldDict);

            fieldDict.AddObject(_IGNORE_CASE, filter.IgnoreCase, CommonGramsTokenFilter._IGNORE_CASE_DEFAULT);
            fieldDict.AddObject(_QUERY_MODE, filter.QueryMode, CommonGramsTokenFilter._QUERY_MODE_DEFAULT);
            if (filter.CommonWords != null && filter.CommonWords.Any(x => !string.IsNullOrWhiteSpace(x)))
            {
                fieldDict.AddObject(_COMMON_WORDS, filter.CommonWords);
            }
            else
            {
                fieldDict.AddObject(_COMMON_WORDS_PATH, filter.CommonWordsPath);
            }            

            Dictionary<string, object> filterDict = new Dictionary<string, object>();
            filterDict.Add(filter.Name, fieldDict);

            serializer.Serialize(writer, filterDict);
        }
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            if (!(value is PercentilesAggregate))
                throw new SerializeTypeException<PercentilesAggregate>();

            PercentilesAggregate agg = value as PercentilesAggregate;

            Dictionary<string, object> fieldDict = new Dictionary<string, object>();
            fieldDict.AddObject(_FIELD, agg.Field);
            agg.Script.Serialize(fieldDict);

            string defaultPercents = JsonConvert.SerializeObject(PercentilesAggregate._PERCENT_BUCKETS_DEFAULT);
            string actualPercents = JsonConvert.SerializeObject(agg.PercentBuckets);

            if (actualPercents != defaultPercents)
                fieldDict.AddObject(_PERCENTS, agg.PercentBuckets);

            fieldDict.AddObject(_COMPRESSION, agg.Compression, PercentilesAggregate._COMPRESSION_DEFAULT);

            Dictionary<string, object> aggDict = new Dictionary<string, object>();
            aggDict.Add(AggregationTypeEnum.Percentiles.ToString(), fieldDict);

            Dictionary<string, object> subAggsDict = agg.SerializeSubAggregations();
            if (subAggsDict != null)
            {
                aggDict.Add(BucketAggregationBase._SUB_AGGREGATIONS, subAggsDict);
            }

            Dictionary<string, object> aggNameDict = new Dictionary<string, object>();
            aggNameDict.Add(agg.Name, aggDict);

            serializer.Serialize(writer, aggNameDict);
        }
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            if (!(value is GeoDistanceAggregate))
                throw new SerializeTypeException<GeoDistanceAggregate>();

            GeoDistanceAggregate agg = value as GeoDistanceAggregate;

            Dictionary<string, object> fieldDict = new Dictionary<string, object>();
            fieldDict.AddObject(_FIELD, agg.Field);
            fieldDict.AddObject(_ORIGIN, agg.OriginPoint);
            fieldDict.AddObject(_UNIT, agg.Unit.ToString(), _UNIT_DEFAULT.ToString());
            fieldDict.AddObject(_DISTANCE_TYPE, agg.DistanceComputeType.ToString(), _DISTANCE_TYPE_DEFAULT.ToString());
            fieldDict.AddObject(_RANGES, agg.Ranges.Select(x => SerializeRangeBucket(x)));
            Dictionary<string, object> aggDict = new Dictionary<string, object>();
            aggDict.Add(AggregationTypeEnum.GeoDistance.ToString(), fieldDict);

            Dictionary<string, object> subAggsDict = agg.SerializeSubAggregations();
            if (subAggsDict != null)
            {
                aggDict.Add(BucketAggregationBase._SUB_AGGREGATIONS, subAggsDict);
            }

            Dictionary<string, object> aggNameDict = new Dictionary<string, object>();
            aggNameDict.Add(agg.Name, aggDict);

            serializer.Serialize(writer, aggNameDict);
        }
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            if (!(value is GeoHashGridAggregate))
                throw new SerializeTypeException<GeoHashGridAggregate>();

            GeoHashGridAggregate agg = value as GeoHashGridAggregate;

            Dictionary<string, object> fieldDict = new Dictionary<string, object>();
            fieldDict.AddObject(_FIELD, agg.Field);
            fieldDict.AddObject(_PRECISION, agg.Precision, _PRECISION_DEFAULT);
            fieldDict.AddObject(_SIZE, agg.Size, _SIZE_DEFAULT);
            fieldDict.AddObject(_SHARD_SIZE, agg.ShardSize, agg.Size);

            Dictionary<string, object> aggDict = new Dictionary<string, object>();
            aggDict.Add(AggregationTypeEnum.GeoHashGrid.ToString(), fieldDict);

            Dictionary<string, object> subAggsDict = agg.SerializeSubAggregations();
            if (subAggsDict != null)
            {
                aggDict.Add(BucketAggregationBase._SUB_AGGREGATIONS, subAggsDict);
            }

            Dictionary<string, object> aggNameDict = new Dictionary<string, object>();
            aggNameDict.Add(agg.Name, aggDict);

            serializer.Serialize(writer, aggNameDict);
        }
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            if (!(value is PatternAnalyzer))
                throw new SerializeTypeException<PatternAnalyzer>();

            PatternAnalyzer analyzer = value as PatternAnalyzer;

            Dictionary<string, object> fieldDict = new Dictionary<string, object>();
            AnalyzerBase.Serialize(analyzer, fieldDict);

            fieldDict.AddObject(_LOWERCASE, analyzer.Lowercase, PatternAnalyzer._LOWERCASE_DEFAULT);
            fieldDict.AddObject(_PATTERN, analyzer.Pattern, PatternAnalyzer._REGEX_PATTERN_DEFAULT);

            if (analyzer.Flags != null && analyzer.Flags.Any(x => x != null))
            {
                fieldDict.AddObject(_FLAGS, string.Join(_FLAG_DELIMITER, analyzer.Flags.Where(x => x != null).Select(x => x.ToString())));
            }

            if (analyzer.Stopwords != null && analyzer.Stopwords.Any(x => !string.IsNullOrWhiteSpace(x)))
            {
                fieldDict.AddObject(_STOPWORDS, analyzer.Stopwords);
            }

            Dictionary<string, object> analyzerDict = new Dictionary<string, object>();
            analyzerDict.Add(analyzer.Name, fieldDict);

            serializer.Serialize(writer, analyzerDict);
        }
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            if (!(value is TypeMapping))
                throw new SerializeTypeException<TypeMapping>();

            TypeMapping prop = value as TypeMapping;

            Dictionary<string, object> fieldDict = new Dictionary<string, object>();
            DocumentMapping.Serialize(prop.Fields, fieldDict);
            PropertyAnalyzer.Serialize(prop.Analyzer, fieldDict);
            fieldDict.AddObject(TypeMapping.DETECT_DATES, prop.DetectDates, TypeMapping._DETECT_DATES_DEFAULT);
            fieldDict.AddObject(TypeMapping.DETECT_NUMBERS, prop.DetectNumbers, TypeMapping._DETECT_NUMBERS_DEFAULT);
            if (prop.DynamicDateFormats != null && prop.DynamicDateFormats.Any(x => x != null))
                fieldDict.Add(TypeMapping.DYNAMIC_DATE_FORMATS, prop.DynamicDateFormats.Where(x => x != null));
            if (prop.DynamicTemplates != null && prop.DynamicTemplates.Any(x => x != null))
                fieldDict.Add(TypeMapping.DYNAMIC_TEMPLATES, prop.DynamicTemplates.Where(x => x != null));
            
            ObjectProperty objProp = new ObjectProperty(prop.Name)
            {
                //CopyTo = prop.CopyTo,
                Dynamic = prop.Dynamic,
                IncludeInAll = prop.IncludeInAll,
                IsEnabled = prop.IsEnabled,
                Properties = prop.Properties
            };
            ObjectProperty.Serialize(objProp, fieldDict);

            if (prop.MetaData != null && prop.MetaData.Any())
                fieldDict.Add(TypeMapping.META, prop.MetaData);

            Dictionary<string, object> propDict = new Dictionary<string,object>();
            propDict.Add(prop.Name, fieldDict);

            serializer.Serialize(writer, propDict);
        }
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            if (!(value is GeoPointProperty))
                throw new SerializeTypeException<GeoPointProperty>();

            GeoPointProperty prop = value as GeoPointProperty;
            Dictionary<string, object> fieldDict = new Dictionary<string, object>();
            DocumentPropertyBase.Serialize(prop, fieldDict);
            fieldDict.AddObject(_INDEX_LAT_LON, prop.IndexLatLon, GeoPointProperty._INDEX_LAT_LON_DEFAULT);
            fieldDict.AddObject(_INDEX_GEO_HASH, prop.IndexGeoHash, GeoPointProperty._INDEX_GEO_HASH_DEFAULT);
            fieldDict.AddObject(_INDEX_GEO_HASH_PREFIX, prop.IndexGeoHashPrefix, GeoPointProperty._INDEX_GEO_HASH_PREFIX_DEFAULT);
            fieldDict.AddObject(_GEO_HASH_PRECISION, prop.GeoHashPrecision, GeoPointProperty._GEO_HASH_PRECISION_DEFAULT);
            fieldDict.AddObject(_VALIDATE, prop.Validate, GeoPointProperty._VALIDATE_DEFAULT);
            fieldDict.AddObject(_VALIDATE_LAT, prop.ValidateLatitude, GeoPointProperty._VALIDATE_LAT_DEFAULT);
            fieldDict.AddObject(_VALIDATE_LON, prop.ValidateLongitude, GeoPointProperty._VALIDATE_LON_DEFAULT);
            fieldDict.AddObject(_NORMALIZE, prop.Normalize, GeoPointProperty._NORMALIZE_DEFAULT);
            fieldDict.AddObject(_NORMALIZE_LAT, prop.NormalizeLatitude, GeoPointProperty._NORMALIZE_LAT_DEFAULT);
            fieldDict.AddObject(_NORMALIZE_LON, prop.NormalizeLongitude, GeoPointProperty._NORMALIZE_LON_DEFAULT);

            if (prop.CompressionPrecision != null && prop.CompressionPrecision.ToString() != GeoPointProperty._COMPRESSION_PRECISION_DEFAULT.ToString())
            {
                Dictionary<string, object> fieldDataDict = new Dictionary<string, object>();
                fieldDataDict.Add(_FORMAT, GeoPointProperty._FIELD_DATA_FORMAT_DEFAULT);
                fieldDataDict.Add(_PRECISION, prop.CompressionPrecision);

                fieldDict.Add(_FIELD_DATA, fieldDataDict);
            }

            Dictionary<string, object> propDict = new Dictionary<string, object>();
            propDict.Add(prop.Name, fieldDict);

            serializer.Serialize(writer, propDict);
        }
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            if (!(value is SnowballAnalyzer))
                throw new SerializeTypeException<SnowballAnalyzer>();

            SnowballAnalyzer analyzer = value as SnowballAnalyzer;

            Dictionary<string, object> fieldDict = new Dictionary<string, object>();
            AnalyzerBase.Serialize(analyzer, fieldDict);
            fieldDict.AddObject(_LANGUAGE, analyzer.Language.ToString(), SnowballAnalyzer._LANGUAGE_DEFAULT.ToString());
            if (analyzer.Stopwords != null)
            {
                if (analyzer.Stopwords == new List<string>() || analyzer.Stopwords.All(x => string.IsNullOrWhiteSpace(x)))
                    fieldDict.Add(_STOPWORDS, SnowballAnalyzer._EMPTY_STOPWORDS_DEFAULT);
                else
                    fieldDict.Add(_STOPWORDS, analyzer.Stopwords);
            }

            fieldDict.AddObject(_STOPWORDS_PATH, analyzer.StopwordsPath);

            Dictionary<string, object> analyzerDict = new Dictionary<string, object>();
            analyzerDict.Add(analyzer.Name, fieldDict);

            serializer.Serialize(writer, analyzerDict);
        }
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            if (!(value is ConstantScoreQueryBase))
                throw new SerializeTypeException<ConstantScoreQueryBase>();

            ConstantScoreQueryBase query = value as ConstantScoreQueryBase;

            Dictionary<string, object> constantDict = new Dictionary<string, object>();
            Dictionary<string, object> internalDict = new Dictionary<string, object>();
            if (value is ConstantScoreQuery)
            {
                internalDict.Add(_QUERY, query.SearchPiece);
            }
            else if (value is ConstantScoreFilter)
            {
                internalDict.Add(_FILTER, query.SearchPiece);
            }
            else
            {
                throw new Exception("Serialization value is not a ConstantScoreQuery or ConstantScoreFilter.");
            }

            internalDict.AddObject(QuerySerializer._BOOST, query.Boost, QuerySerializer._BOOST_DEFAULT);
            internalDict.AddObject(QuerySerializer._QUERY_NAME, query.QueryName);
            constantDict.Add(_CONSTANT_SCORE, internalDict);

            serializer.Serialize(writer, constantDict);
        }
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            if (!(value is DateProperty))
                throw new SerializeTypeException<DateProperty>();

            DateProperty prop = value as DateProperty;

            Dictionary<string, object> fieldDict = new Dictionary<string, object>();
            FieldProperty.Serialize(prop, fieldDict);
            fieldDict.AddObject(_PRECISION_STEP, prop.PrecisionStep, DateProperty._PRECISION_STEP_DEFAULT);
            if (prop.Format != null)
            {
                string formatJson = JsonConvert.SerializeObject(prop.Format);
                string expectedFormatJson = JsonConvert.SerializeObject(DateProperty._FORMAT_DEFAULT);
                if(formatJson != expectedFormatJson)
                    fieldDict.Add(_FORMAT, prop.Format);
            }
            fieldDict.AddObject(_IGNORE_MALFORMED, prop.IgnoreMalformed, DateProperty._IGNORE_MALFORMED_DEFAULT);
            fieldDict.AddObject(_DOC_VALUES, prop.DocValues, DateProperty._DOCS_VALUE_DEFAULT);

            Dictionary<string, object> propDict = new Dictionary<string, object>();
            propDict.Add(prop.Name, fieldDict);

            serializer.Serialize(writer, propDict);
        }
示例#18
0
        private Dictionary<string, object> SerializeRangeBucket(IpRangeBucket bucket)
        {
            Dictionary<string, object> bucketDict = new Dictionary<string, object>();
            bucketDict.AddObject(_TO, bucket.To);
            bucketDict.AddObject(_FROM, bucket.From);

            return bucketDict;
        }
示例#19
0
        internal Dictionary<string, object> Serialize()
        {
            Dictionary<string, object> fieldDict = new Dictionary<string, object>();
            fieldDict.AddObject(_MINIMUM, this.Minimum, _MINIMUM_DEFAULT);
            fieldDict.AddObject(_MAXIMUM, this.Maximum, _MAXIMUM_DEFAULT);
            fieldDict.AddObject(_MINIMUM_SEGMENT_SIZE, this.MinimumSegmentSize, _MINIMUM_SEGMENT_SIZE_DEFAULT);

            return fieldDict;
        }
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            if (!(value is DocumentSize))
                throw new SerializeTypeException<DocumentSize>();

            DocumentSize size = value as DocumentSize;

            Dictionary<string, object> fieldDict = new Dictionary<string, object>();
            fieldDict.AddObject(_IS_ENABLED, size.IsEnabled, DocumentSize._IS_ENABLED_DEFAULT);
            fieldDict.AddObject(_STORE, size.Store, DocumentSize._STORE_DEFAULT);

            serializer.Serialize(writer, fieldDict);
        }
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            if (!(value is DocumentTimeToLive))
                throw new SerializeTypeException<DocumentTimeToLive>();

            DocumentTimeToLive ttl = value as DocumentTimeToLive;

            Dictionary<string, object> fieldDict = new Dictionary<string, object>();
            fieldDict.AddObject(_IS_ENABLED, ttl.IsEnabled, DocumentTimeToLive._IS_ENABLED_DEFAULT);
            MappingBase.Serialize(ttl, fieldDict);
            fieldDict.AddObject(_DEFAULT, ttl.DefaultTimeToLive);

            serializer.Serialize(writer, fieldDict);
        }
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            if (!(value is DocumentRouting))
                throw new SerializeTypeException<DocumentRouting>();

            DocumentRouting routing = value as DocumentRouting;

            Dictionary<string, object> fieldDict = new Dictionary<string, object>();
            MappingBase.Serialize(routing, fieldDict);
            fieldDict.AddObject(_IS_REQUIRED, routing.IsRequired, DocumentRouting._IS_REQUIRED_DEFAULT);
            fieldDict.AddObject(_PATH, routing.Path);

            serializer.Serialize(writer, fieldDict);
        }
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            if (!(value is StringProperty))
                throw new SerializeTypeException<StringProperty>();

            StringProperty property = value as StringProperty;

            Dictionary<string, object> fieldDict = new Dictionary<string, object>();
            FieldProperty.Serialize(property, fieldDict);
            PropertyAnalyzer.Serialize(property.Analyzer, fieldDict);
            fieldDict.AddObject(_DOC_VALUES, property.DocValues, StringProperty._DOC_VALUES_DEFAULT);
            fieldDict.AddObject(_IGNORE_ABOVE, property.IgnoreAbove);
            if (property.IsAnalyzed)
            {
                fieldDict.AddObject(_INDEX_OPTIONS, property.IndexOptions.ToString(), StringProperty._INDEX_OPTION_ANALYZED_DEFAULT.ToString());
                fieldDict.AddObject(_OMIT_NORMS, property.OmitNorms, StringProperty._OMIT_NORMS_ANALYZED_DEFAULT);
            }
            else
            {
                fieldDict.AddObject(_INDEX_OPTIONS, property.IndexOptions.ToString(), StringProperty._INDEX_OPTION_NOT_ANALYZED_DEFAULT.ToString());
                fieldDict.AddObject(_OMIT_NORMS, property.OmitNorms, StringProperty._OMIT_NORMS_NOT_ANALYZED_DEFAULT);
            }
                
            Norms.Serialize(property.Norms, fieldDict, property.IsAnalyzed);
            fieldDict.AddObject(_POSITION_GAP_OFFSET, property.PositionOffsetGap, StringProperty._POSITION_OFFSET_GAP_DEFAULT);
            fieldDict.AddObject(_TERM_VECTOR, property.TermVector.ToString(), StringProperty._TERM_VECTOR_DEFAULT.ToString());

            Dictionary<string, object> propDict = new Dictionary<string, object>();
            propDict.Add(property.Name, fieldDict);

            serializer.Serialize(writer, propDict);
        }
示例#24
0
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            if (!(value is MatchAllQuery))
                throw new SerializeTypeException<MatchAllQuery>();

            MatchAllQuery query = value as MatchAllQuery;

            Dictionary<string, object> fieldDict = new Dictionary<string,object>();
            fieldDict.AddObject(QuerySerializer._BOOST, query.Boost, QuerySerializer._BOOST_DEFAULT);
            fieldDict.AddObject(QuerySerializer._QUERY_NAME, query.QueryName);
            Dictionary<string, object> queryDict = new Dictionary<string, object>();
            queryDict.Add(QueryTypeEnum.MatchAll.ToString(), fieldDict);

            serializer.Serialize(writer, queryDict);
        }
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            if (!(value is DocumentSource))
                throw new SerializeTypeException<DocumentSource>();

            DocumentSource source = value as DocumentSource;

            Dictionary<string, object> fieldDict = new Dictionary<string, object>();
            fieldDict.AddObject(_IS_ENABLED, source.IsEnabled, DocumentSource._IS_ENABLED_DEFAULT);
            fieldDict.AddObject(_IS_COMPRESSED, source.IsCompressed, DocumentSource._IS_COMPRESSED_DEFAULT);
            fieldDict.AddObject(_COMPRESSION_THRESHOLD, source.CompressionThreshold);
            fieldDict.AddObject(_INCLUDES, source.Includes);
            fieldDict.AddObject(_EXCLUDES, source.Excludes);

            serializer.Serialize(writer, fieldDict);
        }
示例#26
0
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            if (!(value is IndicesQuery))
                throw new SerializeTypeException<IndicesQuery>();

            IndicesQuery query = value as IndicesQuery;

            Dictionary<string, object> fieldDict = new Dictionary<string, object>();
            if (query.Indices.Count() > 1)
                fieldDict.Add(_INDICES, query.Indices);
            else
                fieldDict.Add(_INDEX, query.Indices.First());

            fieldDict.Add(_QUERY, query.MatchingQuery);
            if (query.NonMatchingQueryType != null)
                fieldDict.Add(_NON_MATCHING_QUERY, query.NonMatchingQueryType.ToString());
            else
                fieldDict.Add(_NON_MATCHING_QUERY, query.NonMatchingQuery);

            fieldDict.AddObject(QuerySerializer._QUERY_NAME, query.QueryName);

            Dictionary<string, object> queryDict = new Dictionary<string, object>();
            queryDict.Add(QueryTypeEnum.Indices.ToString(), fieldDict);

            serializer.Serialize(writer, queryDict);
        }
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            if (!(value is NGramTokenFilter))
                throw new SerializeTypeException<NGramTokenFilter>();

            NGramTokenFilter filter = value as NGramTokenFilter;
            Dictionary<string, object> fieldDict = new Dictionary<string, object>();
            TokenFilterBase.Serialize(filter, fieldDict);
            fieldDict.AddObject(_MINIMUM_GRAM, filter.MinimumSize, NGramTokenFilter._MINIMUM_SIZE_DEFAULT);
            fieldDict.AddObject(_MAXIMUM_GRAM, filter.MaximumSize, NGramTokenFilter._MAXIMUM_SIZE_DEFAULT);

            Dictionary<string, object> filterDict = new Dictionary<string, object>();
            filterDict.Add(filter.Name, fieldDict);

            serializer.Serialize(writer, filterDict);
        }
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            if (!(value is NestedObjectProperty))
                throw new SerializeTypeException<NestedObjectProperty>();

            NestedObjectProperty prop = value as NestedObjectProperty;
            Dictionary<string, object> fieldDict = new Dictionary<string, object>();
            fieldDict.AddObject(_INCLUDE_IN_PARENT, prop.IncludeInParent, NestedObjectProperty._INCLUDE_IN_PARENT_DEFAULT);
            fieldDict.AddObject(_INCLUDE_IN_ROOT, prop.IncludeInRoot, NestedObjectProperty._INCLUDE_IN_ROOT_DEFAULT);
            ObjectProperty.Serialize(prop, fieldDict);

            Dictionary<string, object> propDict = new Dictionary<string, object>();
            propDict.Add(prop.Name, fieldDict);

            serializer.Serialize(writer, propDict);
        }
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            if (!(value is LimitTokenCountTokenFilter))
                throw new SerializeTypeException<LimitTokenCountTokenFilter>();

            LimitTokenCountTokenFilter filter = value as LimitTokenCountTokenFilter;
            Dictionary<string, object> fieldDict = new Dictionary<string, object>();
            TokenFilterBase.Serialize(filter, fieldDict);

            fieldDict.AddObject(_MAXIMUM_TOKEN_COUNT, filter.MaximumTokenCount, LimitTokenCountTokenFilter._MAXIMUM_TOKEN_COUNT_DEFAULT);
            fieldDict.AddObject(_CONSUME_ALL_TOKENS, filter.ConsumeAllTokens, LimitTokenCountTokenFilter._CONSUME_ALL_TOKENS_DEFAULT);

            Dictionary<string, object> filterDict = new Dictionary<string, object>();
            filterDict.Add(filter.Name, fieldDict);

            serializer.Serialize(writer, filterDict);
        }
示例#30
0
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            if (!(value is ExistsFilter))
                throw new SerializeTypeException<ExistsFilter>();

            ExistsFilter filter = value as ExistsFilter;

            Dictionary<string, object> fieldDict = new Dictionary<string, object>();
            fieldDict.Add(filter.Field, filter.Value);
            fieldDict.AddObject(FilterSerializer._CACHE_KEY, filter.CacheKey);
            fieldDict.AddObject(FilterSerializer._FILTER_NAME, filter.FilterName);

            Dictionary<string, object> queryDict = new Dictionary<string, object>();
            queryDict.Add(FilterTypeEnum.Exists.ToString(), fieldDict);

            serializer.Serialize(writer, queryDict);
        }
        /// <summary>
        /// Looks for an existing object with a matching unique field and merges supplied data with existing data.
        /// </summary>
        /// <param name="values">The field values to set.</param>
        /// <returns>The updated ApiObject.</returns>
        public async Task <T> CreateOrMergeAsync(object values = null)
        {
            var query = new Dictionary <string, object>();

            var json = await ApiRequest.PostAsync <JObject>(
                $"{EndpointPlural}/saveorupdate", query.AddObject(values));

            return(await OnParseCreateOrMergeAsync(json));
        }
示例#32
0
        /// <summary>
        /// This endpoint will add a new object to your database. It can be used for any object type as long as the correct parameters are supplied. This endpoint allows duplication; if you want to avoid duplicates you should merge instead.
        /// </summary>
        /// <param name="objectType">The object type.</param>
        /// <param name="values">Fields to set on the object.</param>
        /// <returns>The created object.</returns>
        public async Task <Dictionary <string, string> > CreateAsync(ApiObjectType objectType, object?values = null, CancellationToken cancellationToken = default)
        {
            var query = new Dictionary <string, object?>
            {
                { "objectID", (int)objectType }
            };

            return(await _apiRequest.PostAsync <Dictionary <string, string> >(
                       "objects", query.AddObject(values), cancellationToken).ConfigureAwait(false));
        }
示例#33
0
        /// <summary>
        /// This endpoint will add a new object to your database. It can be used for any object type as long as the correct parameters are supplied. This endpoint allows duplication; if you want to avoid duplicates you should merge instead.
        /// </summary>
        /// <param name="objectType">The object type.</param>
        /// <param name="values">Fields to set on the object.</param>
        /// <returns>The created object.</returns>
        public async Task <Dictionary <string, string> > CreateAsync(ApiObjectType objectType, object values = null)
        {
            var query = new Dictionary <string, object>
            {
                { "objectID", (int)objectType }
            };

            return(await _apiRequest.PostAsync <Dictionary <string, string> >(
                       "objects", query.AddObject(values)));
        }
示例#34
0
        public static IEnumerable <TDestination> TranslateCollection <TDestination>(this IMappingProcessor processor,
                                                                                    IEnumerable <object> source,
                                                                                    object options)
            where TDestination : class
        {
            Condition.Requires(processor, nameof(processor)).IsNotNull();
            var dictionary = new Dictionary <string, object>();

            dictionary.AddObject(options);
            return(processor.TranslateCollection <TDestination>(source, dictionary));
        }
示例#35
0
        public static IEnumerable <TDestination> TranslateCollection <TSource, TDestination>(this IObjectTranslator <TSource, TDestination> translator,
                                                                                             IEnumerable <TSource> source,
                                                                                             object options)
            where TSource : class
            where TDestination : class
        {
            Condition.Requires(translator, nameof(translator)).IsNotNull();
            var dictionary = new Dictionary <string, object>();

            dictionary.AddObject(options);
            return(translator.TranslateCollection(source, dictionary));
        }
示例#36
0
        /// <summary>
        /// Updates an existing object with given data.
        /// </summary>
        /// <param name="objectId">The ID of the object to update.</param>
        /// <param name="values">Fields to set on the object.</param>
        /// <returns>A dictionary of updated fields.</returns>
        public async Task <T> UpdateAsync(int objectId, object?values = null)
        {
            var query = new Dictionary <string, object?>
            {
                { "id", objectId }
            };

            var json = await ApiRequest.PutAsync <JObject>(
                EndpointPlural, query.AddObject(values)).ConfigureAwait(false);

            return(await OnParseUpdateAsync(json).ConfigureAwait(false));
        }
示例#37
0
        /// <summary>
        /// Looks for an existing object with a matching unique field and merges supplied data with existing data. If no unique field is supplied or if no existing object has a matching unique field, a new object will be created.
        /// </summary>
        /// <param name="objectType">The object type.</param>
        /// <param name="ignoreBlanks">Whether or not blank strings should be ignored upon update. Defaults to false: blank strings passed to this endpoint will overwrite existing value.</param>
        /// <param name="values">Additional properties to set on the object.</param>
        /// <returns>The created or updated object.</returns>
        public async Task <Dictionary <string, string> > CreateOrMergeAsync(ApiObjectType objectType, bool ignoreBlanks = false, object?values = null, CancellationToken cancellationToken = default)
        {
            var query = new Dictionary <string, object?>
            {
                { "objectID", (int)objectType },
                { "ignore_blanks", ignoreBlanks }
            };

            var json = await _apiRequest.PostJsonAsync(
                "objects/saveorupdate", query.AddObject(values), cancellationToken).ConfigureAwait(false);

            return(await json.RunAndCatchAsync(x => x.JsonData().JsonChild("attrs").ToObject <Dictionary <string, string> >()).ConfigureAwait(false));
        }
示例#38
0
        /// <summary>
        /// Updates an existing object with given data.
        /// </summary>
        /// <param name="objectType">The object type.</param>
        /// <param name="objectId">The ID of the object to update.</param>
        /// <param name="values">Fields to set on the object.</param>
        /// <returns>A dictionary of updated fields.</returns>
        public async Task <Dictionary <string, string> > UpdateAsync(ApiObjectType objectType, int objectId, object?values = null, CancellationToken cancellationToken = default)
        {
            var query = new Dictionary <string, object?>
            {
                { "objectID", (int)objectType },
                { "id", objectId }
            };

            var json = await _apiRequest.PutJsonAsync(
                "objects", query.AddObject(values), cancellationToken).ConfigureAwait(false);

            return(await json.RunAndCatchAsync(x => x.JsonData().JsonChild("attrs").ToObject <Dictionary <string, string> >()).ConfigureAwait(false));
        }
        /// <summary>
        /// Looks for an existing object with a matching unique field and merges supplied data with existing data.
        /// </summary>
        /// <param name="values">The field values to set.</param>
        /// <returns>The updated ApiObject.</returns>
        public async Task <T> CreateOrMergeAsync(object?values = null)
        {
            var query = new Dictionary <string, object?>();

            var json = await ApiRequest.PostAsync <JObject>(
                $"{EndpointPlural}/saveorupdate", query.AddObject(values)).ConfigureAwait(false);

            var data = JsonData(json);

            return(await CreateApiObjectAsync(data["attrs"] ?? data).ConfigureAwait(false));

            // return await OnParseCreateOrMergeAsync(json);
        }
示例#40
0
        /// <summary>
        /// Looks for an existing object with a matching unique field and merges supplied data with existing data. If no unique field is supplied or if no existing object has a matching unique field, a new object will be created.
        /// </summary>
        /// <param name="objectType">The object type.</param>
        /// <param name="ignoreBlanks">Whether or not blank strings should be ignored upon update. Defaults to false: blank strings passed to this endpoint will overwrite existing value.</param>
        /// <param name="values">Additional properties to set on the object.</param>
        /// <returns>The created or updated object.</returns>
        public async Task <Dictionary <string, string> > CreateOrMergeAsync(ApiObjectType objectType, bool ignoreBlanks = false, object values = null)
        {
            var query = new Dictionary <string, object>
            {
                { "objectID", (int)objectType },
                { "ignore_blanks", ignoreBlanks }
            };

            var result = await _apiRequest.PostAsync <JObject>(
                "objects/saveorupdate", query.AddObject(values));

            return(result["data"]["attrs"].ToObject <Dictionary <string, string> >());
        }
示例#41
0
        /// <summary>
        /// Updates an existing object with given data.
        /// </summary>
        /// <param name="objectType">The object type.</param>
        /// <param name="objectId">The ID of the object to update.</param>
        /// <param name="values">Fields to set on the object.</param>
        /// <returns>A dictionary of updated fields.</returns>
        public async Task <Dictionary <string, string> > UpdateAsync(ApiObjectType objectType, int objectId, object values = null)
        {
            var query = new Dictionary <string, object>
            {
                { "objectID", (int)objectType },
                { "id", objectId }
            };

            var result = await _apiRequest.PutAsync <JObject>(
                "objects", query.AddObject(values));

            return(result["data"]["attrs"].ToObject <Dictionary <string, string> >());
        }
示例#42
0
        public static void Map <TSource, TDestination>(this IMappingProcessor processor,
                                                       TSource source,
                                                       TDestination destination,
                                                       object options)
            where TSource : class
            where TDestination : class
        {
            Condition.Requires(processor, nameof(processor)).IsNotNull();
            var dictionary = new Dictionary <string, object>();

            dictionary.AddObject(options);
            processor.Map(source, destination, dictionary);
        }
        /// <summary>
        /// Updates an existing object with given data.
        /// </summary>
        /// <param name="objectType">The object type.</param>
        /// <param name="objectId">The ID of the object to update.</param>
        /// <param name="values">Fields to set on the object.</param>
        /// <returns>A dictionary of updated fields.</returns>
        public async Task <Dictionary <string, string> > UpdateAsync(ApiObjectType objectType, int objectId, object?values = null)
        {
            var query = new Dictionary <string, object?>
            {
                { "objectID", (int)objectType },
                { "id", objectId }
            };

            var json = await _apiRequest.PutAsync <JObject>(
                "objects", query.AddObject(values)).ConfigureAwait(false);

            return(JsonData(json)["attrs"]?.ToObject <Dictionary <string, string> >()
                   ?? throw new NullReferenceException(Properties.Resources.ResponseDataNull));
        }
        /// <summary>
        /// Looks for an existing object with a matching unique field and merges supplied data with existing data. If no unique field is supplied or if no existing object has a matching unique field, a new object will be created.
        /// </summary>
        /// <param name="objectType">The object type.</param>
        /// <param name="ignoreBlanks">Whether or not blank strings should be ignored upon update. Defaults to false: blank strings passed to this endpoint will overwrite existing value.</param>
        /// <param name="values">Additional properties to set on the object.</param>
        /// <returns>The created or updated object.</returns>
        public async Task <Dictionary <string, string> > CreateOrMergeAsync(ApiObjectType objectType, bool ignoreBlanks = false, object?values = null)
        {
            var query = new Dictionary <string, object?>
            {
                { "objectID", (int)objectType },
                { "ignore_blanks", ignoreBlanks }
            };

            var json = await _apiRequest.PostAsync <JObject>(
                "objects/saveorupdate", query.AddObject(values)).ConfigureAwait(false);

            return(JsonData(json)["attrs"]?.ToObject <Dictionary <string, string> >()
                   ?? throw new NullReferenceException(Properties.Resources.ResponseDataNull));
        }