Example #1
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);
        }
Example #2
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);
        }
Example #3
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 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 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);
        }
        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 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 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 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 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);
        }
Example #14
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 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 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);
        }
        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);
        }
        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;
        }
Example #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 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);
        }
        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 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 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);
        }
Example #25
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 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);
        }
        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 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);
        }
Example #29
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);
        }
        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);
        }