internal static IEnumerable<IAggregation> DeserializeSubAggregations(Dictionary<string, object> aggDict)
        {
            Dictionary<string, object> subAggsDict = null;
            if (aggDict.ContainsKey(BucketAggregationBase._SUB_AGGREGATIONS))
            {
                subAggsDict = JsonConvert.DeserializeObject<Dictionary<string, object>>(aggDict.GetString(_SUB_AGGREGATIONS));
            }
            else if (aggDict.ContainsKey(BucketAggregationBase._SUB_AGGREGATIONS_ABBR))
            {
                subAggsDict = JsonConvert.DeserializeObject<Dictionary<string, object>>(aggDict.GetString(_SUB_AGGREGATIONS_ABBR));
            }
            else
                return null;

            List<IAggregation> subAggregations = new List<IAggregation>();

            AggregationTypeEnum aggType = AggregationTypeEnum.Average;
            foreach (KeyValuePair<string, object> aggKvp in subAggsDict)
            {
                Dictionary<string, object> aggTypeDict = JsonConvert.DeserializeObject<Dictionary<string, object>>(aggKvp.Value.ToString());

                aggType = AggregationTypeEnum.Find(aggTypeDict.First().Key);
                if(aggType == null)
                    throw new Exception(aggTypeDict.First().Key + " is not a value aggregation type.");

                Dictionary<string, object> subAggDict = new Dictionary<string, object>();
                subAggDict.Add(aggKvp.Key, aggKvp.Value);

                string subAggJson = JsonConvert.SerializeObject(subAggDict);
                subAggregations.Add(JsonConvert.DeserializeObject(subAggJson, aggType.ImplementationType) as IAggregation);
            }

            return subAggregations;
        }
        private IpRangeBucket DeserializeRangeBucket(Dictionary<string, object> bucketDict)
        {
            IpRangeBucket bucket = new IpRangeBucket();
            if (bucketDict.ContainsKey(_TO))
                bucket.To = bucketDict.GetString(_TO);
            if (bucketDict.ContainsKey(_FROM))
                bucket.From = bucketDict.GetString(_FROM);

            return bucket;
        }
Example #3
0
        internal static FieldDataFilter Deserialize(Dictionary<string, object> fieldDict)
        {
            if (fieldDict == null || !fieldDict.Any())
                return null;

            if (fieldDict.ContainsKey(_FREQUENCY))
            {
                return new FieldDataFilter(fieldDict.GetString(_REGEX_PATTERN), Frequency.Deserialize(JsonConvert.DeserializeObject<Dictionary<string, object>>(fieldDict.GetString(_FREQUENCY))));
            }

            return new FieldDataFilter(fieldDict.GetString(_REGEX_PATTERN));
        }
Example #4
0
 internal static void DeserializeFacetInfo(FacetBase facet, Dictionary<string, object> facetDict)
 {
     if (facetDict.ContainsKey(_FACET_FILTER))
         facet.FacetFilter = JsonConvert.DeserializeObject<IFilter>(facetDict.GetString(_FACET_FILTER));
     facet.IsScopeGlobal = facetDict.GetBool(_GLOBAL, _GLOBAL_DEFAULT);
     facet.NestedObject = facetDict.GetStringOrDefault(_NESTED);
     facet.Size = facetDict.GetInt32(_SIZE, _SIZE_DEFAULT);
 }
        internal static void Deserialize(DocumentPropertyBase prop, Dictionary<string, object> fieldDict)
        {
            if (!fieldDict.Any())
                return;

            MappingBase.Deserialize(prop, fieldDict);
            prop.IncludeInAll = fieldDict.GetBool(_INCLUDE_IN_ALL, _INCLUDE_IN_ALL_DEFAULT);
            prop.IndexName = fieldDict.GetStringOrDefault(_INDEX_NAME);
            prop.PropertyType = PropertyTypeEnum.Find(fieldDict.GetString(_TYPE, _PROPERTY_TYPE_DEFAULT.ToString()));
        }
Example #6
0
        internal static void Deserialize(MappingBase mappingBase, Dictionary<string, object> fieldDict)
        {
            if (fieldDict == null || !fieldDict.Any())
                return;

            IndexSettingEnum indexSetting = IndexSettingEnum.No;
            mappingBase.Index = IndexSettingEnum.Find(fieldDict.GetString(_INDEX_KEY, mappingBase._INDEX_DEFAULT.ToString()));

            StoreSettingEnum storeSetting = StoreSettingEnum.No;
            mappingBase.Store = fieldDict.GetBool(_STORE_KEY, mappingBase._STORE_DEFAULT);
        }
Example #7
0
        internal static void Deserialize(AnalyzerBase analyzer, Dictionary<string, object> fieldDict)
        {
            if (fieldDict == null || !fieldDict.Any())
                return;

            analyzer.Version = fieldDict.GetDoubleOrNull(_VERSION);
            if (fieldDict.ContainsKey(_ALIASES))
            {
                analyzer.Aliases = JsonConvert.DeserializeObject<IEnumerable<string>>(fieldDict.GetString(_ALIASES));
            }
        }
Example #8
0
        internal static Norms Deserialize(Dictionary<string, object> fieldDict, bool isAnalyzed = true)
        {
            if (fieldDict == null || !fieldDict.ContainsKey(_NORMS))
                return null;

            Norms norms = new Norms();
            Dictionary<string, object> normsDict = JsonConvert.DeserializeObject<Dictionary<string, object>>(fieldDict.GetString(_NORMS));
            if (isAnalyzed)
                norms.IsEnabled = normsDict.GetBool(_IS_ENABLED, _IS_ENABLED_ANALYZED_DEFAULT);
            else
                norms.IsEnabled = normsDict.GetBool(_IS_ENABLED, _IS_ENABLED_NOT_ANALYZED_DEFAULT);

            norms.Loading = NormLoadingEnum.Find(normsDict.GetString(_LOADING, _LOADING_DEFAULT.ToString()));

            return norms;
        }
Example #9
0
        internal static DocumentMapping Deserialize(Dictionary<string, object> fieldDict)
        {
            DocumentMapping mapping = new DocumentMapping();
            if (fieldDict.ContainsKey(_ALL))
                mapping.All = JsonConvert.DeserializeObject<All>(fieldDict.GetString(_ALL));
            if (fieldDict.ContainsKey(_ANALYZER))
                mapping.Analyzer = JsonConvert.DeserializeObject<DocumentAnalyzer>(fieldDict.GetString(_ANALYZER));
            if (fieldDict.ContainsKey(_ID))
                mapping.Id = JsonConvert.DeserializeObject<DocumentIdentifier>(fieldDict.GetString(_ID));
            if (fieldDict.ContainsKey(_INDEX))
                mapping.Index = JsonConvert.DeserializeObject<DocumentIndex>(fieldDict.GetString(_INDEX));
            if (fieldDict.ContainsKey(_PARENT))
                mapping.Parent = JsonConvert.DeserializeObject<ParentType>(fieldDict.GetString(_PARENT));
            if (fieldDict.ContainsKey(_ROUTING))
                mapping.Routing = JsonConvert.DeserializeObject<DocumentRouting>(fieldDict.GetString(_ROUTING));
            if (fieldDict.ContainsKey(_SIZE))
                mapping.Size = JsonConvert.DeserializeObject<DocumentSize>(fieldDict.GetString(_SIZE));
            if (fieldDict.ContainsKey(_SOURCE))
                mapping.Source = JsonConvert.DeserializeObject<DocumentSource>(fieldDict.GetString(_SOURCE));
            if (fieldDict.ContainsKey(_TIME_TO_LIVE))
                mapping.TimeToLive = JsonConvert.DeserializeObject<DocumentTimeToLive>(fieldDict.GetString(_TIME_TO_LIVE));
            if (fieldDict.ContainsKey(_TIMESTAMP))
                mapping.Timestamp = JsonConvert.DeserializeObject<DocumentTimestamp>(fieldDict.GetString(_TIMESTAMP));
            if (fieldDict.ContainsKey(_TYPE))
                mapping.Type = JsonConvert.DeserializeObject<DocumentType>(fieldDict.GetString(_TYPE));

            return mapping;
        }
Example #10
0
        internal static void Deserialize(ObjectProperty prop, Dictionary<string, object> fieldDict)
        {
            if (fieldDict == null || !fieldDict.Any())
                return;

            if (fieldDict.ContainsKey(_COPY_TO))
            {
                try
                {
                    prop.CopyTo = JsonConvert.DeserializeObject<IEnumerable<string>>(fieldDict.GetString(_COPY_TO));
                }
                catch
                {
                    prop.CopyTo = new List<string>() { fieldDict.GetString(_COPY_TO) };
                }
            }

            prop.Dynamic = DynamicSettingEnum.Find(fieldDict.GetString(_DYNAMIC, _DYNAMIC_DEFAULT.ToString()));
            prop.IncludeInAll = fieldDict.GetBool(_INCLUDE_IN_ALL, _INCLUDE_IN_ALL_DEFAULT);
            prop.IsEnabled = fieldDict.GetBool(_IS_ENABLED, _IS_ENABLED_DEFAULT);

            if (fieldDict.ContainsKey(_PROPERTIES))
            {
                prop.Properties = JsonConvert.DeserializeObject<DocumentPropertyCollection>(fieldDict.GetString(_PROPERTIES));
            }
        }
        private GeoBoundingBoxFilter RetrieveBox(string fieldName, Dictionary<string, object> boxDict)
        {
            // maybe are are dealing with the vertices
            if (boxDict.Count() == 4)
                return GetBoxFromVertices(fieldName, boxDict);

            CoordinatePoint topLeft;
            CoordinatePoint bottomRight;
            if (boxDict.ContainsKey(_TOP_LEFT))
            {
                topLeft = CoordinatePointSerializer.DeserializeCoordinatePoint(boxDict.GetString(_TOP_LEFT));
                bottomRight = CoordinatePointSerializer.DeserializeCoordinatePoint(boxDict.GetString(_BOTTOM_RIGHT));
            }
            else if (boxDict.ContainsKey(_TOP_RIGHT))
            {
                CoordinatePoint topRight = CoordinatePointSerializer.DeserializeCoordinatePoint(boxDict.GetString(_TOP_RIGHT));
                CoordinatePoint bottomLeft = CoordinatePointSerializer.DeserializeCoordinatePoint(boxDict.GetString(_BOTTOM_LEFT));

                topLeft = new CoordinatePoint(topRight.Latitude, bottomLeft.Longitude);
                bottomRight = new CoordinatePoint(bottomLeft.Latitude, topRight.Longitude);
            }
            else
            {
                throw new Exception("No bounding box formed by current properties.");
            }

            return new GeoBoundingBoxFilter(fieldName, topLeft, bottomRight);
        }
Example #12
0
 private void ReadFieldsDict(Dictionary<string, object> fieldsDict, MatchQueryBase matchQuery)
 {
     matchQuery.Analyzer = fieldsDict.GetStringOrDefault(_ANALYZER);
     matchQuery.CutOffFrequency = fieldsDict.GetDouble(_CUTOFF_FREQUENCY, _CUTOFF_FREQUENCY_DEFAULT);
     matchQuery.Fuzziness = fieldsDict.GetDouble(_FUZZINESS, _FUZZINESS_DEFAULT);
     matchQuery.IsLenient = fieldsDict.GetBool(_LENIENT, _LENIENT_DEFAULT);
     matchQuery.MaximumExpansions = fieldsDict.GetInt32OrNull(_MAX_EXPANSIONS);
     matchQuery.MinimumShouldMatch = fieldsDict.GetInt32(_MINIMUM_SHOULD_MATCH, _MINIMUM_SHOULD_MATCH_DEFAULT);
     matchQuery.Operator = OperatorEnum.Find(fieldsDict.GetString(_OPERATOR, _OPERATOR_DEFAULT.ToString()));
     matchQuery.PrefixLength = fieldsDict.GetInt32(_PREFIX_LENGTH, _PREFIX_LENGTH_DEFAULT);
     matchQuery.RewriteMethod = RewriteMethodsEnum.Find(fieldsDict.GetString(_REWRITE, "not a real object"));
     matchQuery.ZeroTerm = ZeroTermsEnum.Find(fieldsDict.GetString(_ZERO_TERMS_QUERY, _ZERO_TERMS_QUERY_DEFAULT.ToString()));
     matchQuery.QueryName = fieldsDict.GetStringOrDefault(QuerySerializer._QUERY_NAME);
 }
Example #13
0
        internal static void Deserialize(FieldProperty field, Dictionary<string, object> fieldDict)
        {
            MappingBase.Deserialize(field, fieldDict);
            field.IncludeInAll = fieldDict.GetBool(_INCLUDE_IN_ALL, _INCLUDE_IN_ALL_DEFAULT);
            field.Boost = fieldDict.GetDouble(_BOOST, _BOOST_DEFAULT);

            if (fieldDict.ContainsKey(_COPY_TO))
            {
                try 
                {
                    field.CopyTo = JsonConvert.DeserializeObject<IEnumerable<string>>(fieldDict.GetString(_COPY_TO));
                }
                catch
                {
                    field.CopyTo = new List<string>(){ fieldDict.GetString(_COPY_TO) };
                }
            }

            field.DocValuesFormat = DocValuesFormatEnum.Find(fieldDict.GetString(_DOC_VALUES_FORMAT, _DOC_VALUES_FORMAT_DEFAULT.ToString()));

            if(fieldDict.ContainsKey(_FIELD_DATA))
            {
                field.FieldData = FieldDataFilter.Deserialize(JsonConvert.DeserializeObject<Dictionary<string, object>>(fieldDict.GetString(_FIELD_DATA)));
            }
            
            if(fieldDict.ContainsKey(_FIELDS))
            {
                field.Fields = JsonConvert.DeserializeObject<DocumentPropertyCollection>(fieldDict.GetString(_FIELDS));
            }

            field.IndexName = fieldDict.GetString(_INDEX_NAME, field.Name);
            if(fieldDict.ContainsKey(_NULL_VALUE))
                field.NullValue = fieldDict[_NULL_VALUE];

            field.PostingsFormat = PostingFormatEnum.Find(fieldDict.GetString(_POSTINGS_FORMAT, _POSTINGS_FORMAT_DEFAULT.ToString()));
            field.Similarity = SimilarityAlgorithmEnum.Find(fieldDict.GetString(_SIMILARITY, _SIMILARITY_DEFAULT.ToString()));
        }
        internal static void DeserializeHighlighterOptions(HighlighterOptions options, Dictionary<string, object> fieldDict)
        {
            if(fieldDict == null || !fieldDict.Any())
                return;

            options.BoundaryCharacters = fieldDict.GetString(_BOUNDARY_CHARACTERS, _BOUNDARY_CHARACTERS_DEFAULT);
            options.BoundaryMaximumScan = fieldDict.GetInt32(_BOUNDARY_MAXIMUM_SCAN, _BOUNDARY_MAXIMUM_SCAN_DEFAULT);
            options.Encoder = EncoderTypeEnum.Find(fieldDict.GetString(_ENCODER, _ENCODER_DEFAULT.ToString()));
            options.FragmentSize = fieldDict.GetInt32(_FRAGMENT_SIZE, _FRAGMENT_SIZE_DEFAULT);
            options.NoMatchSize = fieldDict.GetInt32(_NO_MATCH_SIZE, _NO_MATCH_SIZE_DEFAULT);
            options.NumberOfFragments = fieldDict.GetInt32(_NUMBER_OF_FRAGMENTS, _NUMBER_OF_FRAGMENTS_DEFAULT);
            options.PhraseLimit = fieldDict.GetInt32(_PHRASE_LIMIT, _PHRASE_LIMIT_DEFAULT);
            if(fieldDict.ContainsKey(_POST_TAGS))
                options.PostTags = JsonConvert.DeserializeObject<IEnumerable<string>>(fieldDict.GetString(_POST_TAGS));
            if(fieldDict.ContainsKey(_PRE_TAGS))
                options.PreTags = JsonConvert.DeserializeObject<IEnumerable<string>>(fieldDict.GetString(_PRE_TAGS));
            options.RequireFieldMatch = fieldDict.GetBool(_REQUIRE_FIELD_MATCH, _REQUIRE_FIELD_MATCH_DEFAULT);
            options.TagsSchema = TagsSchemaEnum.Find(fieldDict.GetString(_TAGS_SCHEMA, _TAGS_SCHEMA_DEFAULT.ToString()));
            options.Type = HighlighterTypeEnum.Find(fieldDict.GetString(_HIGHLIGHTER_TYPE, _HIGHLIGHTER_TYPE_DEFAULT.ToString()));
        }
Example #15
0
        internal static PropertyAnalyzer Deserialize(Dictionary<string, object> fieldDict)
        {
            if (fieldDict == null || !fieldDict.Any())
                return null;

            PropertyAnalyzer propertyAnalyzer = null;
            if (fieldDict.ContainsKey(_ANALYZER))
            {
                propertyAnalyzer = new PropertyAnalyzer(GetAnalyzer(fieldDict.GetString(_ANALYZER)));
            }
            else if (fieldDict.ContainsKey(_INDEX_ANALYZER))
            {
                IAnalyzer searchAnalyzer = null;
                try 
                { 
                    searchAnalyzer = GetAnalyzer(fieldDict.GetStringOrDefault(_SEARCH_ANALYZER));
                }
                catch{}

                propertyAnalyzer = new PropertyAnalyzer(
                    GetAnalyzer(fieldDict.GetString(_INDEX_ANALYZER)),
                    searchAnalyzer);
            }

            return propertyAnalyzer;
        }