protected bool Equals(IndexMappingProperty other)
 {
     return(System.String.Equals(Index, other.Index) && System.String.Equals(Analyzer, other.Analyzer) &&
            System.String.Equals(Type, other.Type) && System.String.Equals(Format, other.Format) &&
            FieldData == other.FieldData &&
            (CopyTo == null && other.CopyTo == null || CopyTo?.SequenceEqual(other.CopyTo) == true));
 }
Beispiel #2
0
        public void AddOrUpdateProperty(string name, IndexMappingProperty property)
        {
            Logger.Debug("Property: " + name);

            if (property == null)
            {
                property = new IndexMappingProperty
                {
                    Type = nameof(MappingType.Text).ToLower()
                };
            }

            if (!Properties.ContainsKey(name))
            {
                Logger.Debug("Adding property");
                Properties.Add(name, property);
                IsDirty = true;
            }

            if (property.Analyzer != null)
            {
                Logger.Debug("Analyzer: " + property.Analyzer);

                if (Properties[name].Analyzer != property.Analyzer)
                {
                    IsDirty = true;
                }

                Properties[name].Analyzer = property.Analyzer;
            }

            if (property.Format != null)
            {
                Logger.Debug("Format: " + property.Format);

                if (Properties[name].Format != property.Format)
                {
                    IsDirty = true;
                }

                Properties[name].Format = property.Format;
            }

            if (property.Type != null)
            {
                Logger.Debug("Type: " + property.Type);

                if (Properties[name].Type != property.Type)
                {
                    IsDirty = true;
                }

                if (property.Type == nameof(MappingType.Text).ToLower())
                {
                    Logger.Debug("Type is string");
                    property.Fields = property.Fields ?? new IndexMappingProperty.ContentProperty();
                    property.Fields.KeywordSettings = new IndexMappingProperty.ContentProperty.Keyword
                    {
                        IgnoreAbove = 256,
                        Type        = JsonNames.Keyword
                    };
                }
                else if (property.Type == nameof(MappingType.Object).ToLower())
                {
                    Logger.Debug("Type is Object");
                    property.Dynamic    = true;
                    property.Properties = new Dictionary <string, object>();
                }

                Properties[name].Type = property.Type;
            }

            if (Properties[name].CopyTo != null && !Properties[name].CopyTo.SequenceEqual(property.CopyTo))
            {
                IsDirty = true;
                Properties[name].CopyTo = property.CopyTo;
            }

            if (Properties[name].CopyTo != null)
            {
                Logger.Debug("CopyTo: " + String.Join(", ", Properties[name].CopyTo));
            }
        }
        public void AddOrUpdateProperty(string name, IndexMappingProperty property)
        {
            Logger.Debug("Property: " + name);

            if (property == null)
            {
                property = new IndexMappingProperty
                {
                    Type = nameof(MappingType.Text).ToLower()
                };
            }

            if (!Properties.ContainsKey(name))
            {
                Logger.Debug("Adding property");
                Properties.Add(name, property);
                IsDirty = true;
            }

            if (property.Analyzer != null)
            {
                Logger.Debug("Analyzer: " + property.Analyzer);

                if (Properties[name].Analyzer != property.Analyzer)
                {
                    IsDirty = true;
                }
                Properties[name].Analyzer = property.Analyzer;
            }

            if (property.Format != null)
            {
                Logger.Debug("Format: " + property.Format);

                if (Properties[name].Format != property.Format)
                {
                    IsDirty = true;
                }
                Properties[name].Format = property.Format;
            }

            if (property.Type != null)
            {
                Logger.Debug("Type: " + property.Type);

                if (Properties[name].Type != property.Type)
                {
                    IsDirty = true;
                }

                if (property.Type == nameof(MappingType.Text).ToLower())
                {
                    Logger.Debug("Type is string");
                    property.Fields = property.Fields ?? new IndexMappingProperty.ContentProperty();
                    property.Fields.KeywordSettings = new IndexMappingProperty.ContentProperty.Keyword
                    {
                        IgnoreAbove = 256,
                        Type        = JsonNames.Keyword
                    };
                }

                Properties[name].Type = property.Type;
            }

            if (IncludeInDidYouMean(name, property))
            {
                Logger.Debug("Should include in DidYouMean");

                if (property.CopyTo == null || property.CopyTo.Length == 0)
                {
                    property.CopyTo = new[] { DefaultFields.DidYouMean };
                    IsDirty         = true;
                }
                else if (!property.CopyTo.Contains(DefaultFields.DidYouMean))
                {
                    property.CopyTo = property.CopyTo.Concat(new[] { DefaultFields.DidYouMean }).ToArray();
                    IsDirty         = true;
                }

                Properties[name].CopyTo = property.CopyTo;
            }

            if (Properties[name].CopyTo != null)
            {
                Logger.Debug("CopyTo: " + String.Join(", ", Properties[name].CopyTo));
            }
        }
 private static bool IncludeInDidYouMean(string name, IndexMappingProperty property)
 {
     return(name != null &&
            property.Type == nameof(MappingType.Text).ToLower() &&
            !WellKnownProperties.IgnoreDidYouMean.Contains(name));
 }