From a8b121beb5d65c64dffe030cff43bfe310e284e5 Mon Sep 17 00:00:00 2001 From: gmarz Date: Thu, 14 Jan 2016 10:52:28 -0500 Subject: [PATCH 1/2] Implement descriptor for norms and renamed from NormsMapping => Norms Relates #1723 --- .../Mapping/AttributeBased/StringAttribute.cs | 2 +- src/Nest/Mapping/Norms/Norms.cs | 33 +++++++++++++++++++ src/Nest/Mapping/Norms/NormsMapping.cs | 17 ---------- .../Types/Core/String/StringProperty.cs | 10 +++--- src/Nest/Nest.csproj | 2 +- .../Types/Core/String/StringMappingTests.cs | 24 ++++++++++++++ .../Mapping/Types/TypeMappingTestBase.cs | 14 +++++++- src/Tests/tests.yaml | 2 +- 8 files changed, 78 insertions(+), 26 deletions(-) create mode 100644 src/Nest/Mapping/Norms/Norms.cs delete mode 100644 src/Nest/Mapping/Norms/NormsMapping.cs diff --git a/src/Nest/Mapping/AttributeBased/StringAttribute.cs b/src/Nest/Mapping/AttributeBased/StringAttribute.cs index 6544a03d143..4fc5522cadd 100644 --- a/src/Nest/Mapping/AttributeBased/StringAttribute.cs +++ b/src/Nest/Mapping/AttributeBased/StringAttribute.cs @@ -8,7 +8,7 @@ public class StringAttribute : ElasticsearchPropertyAttribute, IStringProperty TermVectorOption? IStringProperty.TermVector { get; set; } double? IStringProperty.Boost { get; set; } string IStringProperty.NullValue { get; set; } - NormsMapping IStringProperty.Norms { get; set; } + INorms IStringProperty.Norms { get; set; } IndexOptions? IStringProperty.IndexOptions { get; set; } string IStringProperty.Analyzer { get; set; } string IStringProperty.SearchAnalyzer { get; set; } diff --git a/src/Nest/Mapping/Norms/Norms.cs b/src/Nest/Mapping/Norms/Norms.cs new file mode 100644 index 00000000000..b477b01d548 --- /dev/null +++ b/src/Nest/Mapping/Norms/Norms.cs @@ -0,0 +1,33 @@ +using System; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; + +namespace Nest +{ + [JsonObject(MemberSerialization.OptIn)] + [JsonConverter(typeof(ReadAsTypeJsonConverter))] + public interface INorms + { + [JsonProperty("enabled")] + bool? Enabled { get; set; } + + [JsonProperty("loading")] + [JsonConverter(typeof(StringEnumConverter))] + NormsLoading? Loading { get; set; } + } + + public class Norms : INorms + { + public bool? Enabled { get; set; } + public NormsLoading? Loading { get; set; } + } + + public class NormsDescriptor : DescriptorBase, INorms + { + bool? INorms.Enabled { get; set; } + NormsLoading? INorms.Loading { get; set; } + + public NormsDescriptor Enabled(bool enabled = true) => Assign(a => a.Enabled = enabled); + public NormsDescriptor Loading(NormsLoading loading) => Assign(a => a.Loading = loading); + } +} \ No newline at end of file diff --git a/src/Nest/Mapping/Norms/NormsMapping.cs b/src/Nest/Mapping/Norms/NormsMapping.cs deleted file mode 100644 index ede75cc730a..00000000000 --- a/src/Nest/Mapping/Norms/NormsMapping.cs +++ /dev/null @@ -1,17 +0,0 @@ -using Newtonsoft.Json; -using Newtonsoft.Json.Converters; - -namespace Nest -{ - [JsonObject(MemberSerialization.OptIn)] - public class NormsMapping - { - [JsonProperty("enabled")] - public bool? Enabled { get; set; } - - [JsonProperty("loading")] - [JsonConverter(typeof(StringEnumConverter))] - public NormsLoading? Loading { get; set; } - - } -} \ No newline at end of file diff --git a/src/Nest/Mapping/Types/Core/String/StringProperty.cs b/src/Nest/Mapping/Types/Core/String/StringProperty.cs index 2e845e024b9..83d79cd1831 100644 --- a/src/Nest/Mapping/Types/Core/String/StringProperty.cs +++ b/src/Nest/Mapping/Types/Core/String/StringProperty.cs @@ -19,7 +19,7 @@ public interface IStringProperty : IProperty string NullValue { get; set; } [JsonProperty("norms")] - NormsMapping Norms { get; set; } + INorms Norms { get; set; } [JsonProperty("index_options")] IndexOptions? IndexOptions { get; set; } @@ -51,7 +51,7 @@ public StringProperty() : base("string") { } public TermVectorOption? TermVector { get; set; } public double? Boost { get; set; } public string NullValue { get; set; } - public NormsMapping Norms { get; set; } + public INorms Norms { get; set; } public IndexOptions? IndexOptions { get; set; } public string Analyzer { get; set; } public string SearchAnalyzer { get; set; } @@ -69,7 +69,7 @@ public class StringPropertyDescriptor TermVectorOption? IStringProperty.TermVector { get; set; } double? IStringProperty.Boost { get; set; } string IStringProperty.NullValue { get; set; } - NormsMapping IStringProperty.Norms { get; set; } + INorms IStringProperty.Norms { get; set; } IndexOptions? IStringProperty.IndexOptions { get; set; } string IStringProperty.Analyzer { get; set; } string IStringProperty.SearchAnalyzer { get; set; } @@ -99,7 +99,7 @@ public StringPropertyDescriptor() : base("string") { } public StringPropertyDescriptor SearchAnalyzer(string searchAnalyzer) => Assign(a => a.SearchAnalyzer = searchAnalyzer); - public StringPropertyDescriptor Norms(NormsMapping normsMapping) => Assign(a => a.Norms = normsMapping); + public StringPropertyDescriptor Norms(Func selector) => Assign(a => a.Norms = selector?.Invoke(new NormsDescriptor())); public StringPropertyDescriptor IgnoreAbove(int ignoreAbove) => Assign(a => a.IgnoreAbove = ignoreAbove); @@ -108,6 +108,6 @@ public StringPropertyDescriptor() : base("string") { } public StringPropertyDescriptor PositionOffsetGap(int positionOffsetGap) => Assign(a => a.PositionOffsetGap = positionOffsetGap); public StringPropertyDescriptor Fielddata(Func selector) => - Assign(a => selector(new StringFielddataDescriptor())); + Assign(a => a.Fielddata = selector?.Invoke(new StringFielddataDescriptor())); } } \ No newline at end of file diff --git a/src/Nest/Nest.csproj b/src/Nest/Nest.csproj index 38707710a4b..524db43d06c 100644 --- a/src/Nest/Nest.csproj +++ b/src/Nest/Nest.csproj @@ -509,7 +509,7 @@ - + diff --git a/src/Tests/Mapping/Types/Core/String/StringMappingTests.cs b/src/Tests/Mapping/Types/Core/String/StringMappingTests.cs index 0fadfd0d37a..d83f0b0dd14 100644 --- a/src/Tests/Mapping/Types/Core/String/StringMappingTests.cs +++ b/src/Tests/Mapping/Types/Core/String/StringMappingTests.cs @@ -102,5 +102,29 @@ public class StringMappingTests : TypeMappingTestBase .String(s => s .Name(o => o.Guid) ); + + protected override object ExpectJsonFluentOnly => new + { + properties = new + { + full = new + { + type = "string", + norms = new + { + enabled = true, + loading = "lazy" + } + } + } + }; + protected override Func, IPromise> FluentOnlyProperties => p => p + .String(s => s + .Name(o => o.Full) + .Norms(n => n + .Enabled() + .Loading(NormsLoading.Lazy) + ) + ); } } diff --git a/src/Tests/Mapping/Types/TypeMappingTestBase.cs b/src/Tests/Mapping/Types/TypeMappingTestBase.cs index 90a6353c050..cbba82cf562 100644 --- a/src/Tests/Mapping/Types/TypeMappingTestBase.cs +++ b/src/Tests/Mapping/Types/TypeMappingTestBase.cs @@ -10,16 +10,28 @@ public abstract class TypeMappingTestBase { protected abstract object ExpectJson { get; } + protected virtual object ExpectJsonFluentOnly { get; } + protected abstract Func, IPromise> FluentProperties { get; } + protected virtual Func, IPromise> FluentOnlyProperties { get; } + [U] protected virtual void AttributeBasedSerializes() => Expect(ExpectJson) .WhenSerializing(new PutMappingDescriptor().AutoMap() as IPutMappingRequest); [U] - protected virtual void CodeBasedSerializes() => + protected virtual void CodeBasedSerializes() + { Expect(ExpectJson) .WhenSerializing(new PutMappingDescriptor().Properties(FluentProperties) as IPutMappingRequest); + + if (ExpectJsonFluentOnly != null) + { + Expect(ExpectJsonFluentOnly) + .WhenSerializing(new PutMappingDescriptor().Properties(FluentOnlyProperties) as IPutMappingRequest); + } + } } } diff --git a/src/Tests/tests.yaml b/src/Tests/tests.yaml index cb0f500286c..0bf5e1a4827 100644 --- a/src/Tests/tests.yaml +++ b/src/Tests/tests.yaml @@ -1,5 +1,5 @@ # mode either u (unit test), i (integration test) or m (mixed mode) -mode: i +mode: u # the elasticsearch version that should be started elasticsearch_version: 2.0.1 # whether we want to forcefully reseed on the node, if you are starting the tests with a node already running From 70050431117d6b7b2dc39057456c8cc4de9db4fd Mon Sep 17 00:00:00 2001 From: gmarz Date: Thu, 14 Jan 2016 11:14:08 -0500 Subject: [PATCH 2/2] Move attribute types to their respective folders --- .../{CodeBased => }/PropertyMapping.cs | 0 .../Complex/Nested}/NestedAttribute.cs | 0 .../Complex/Object}/ObjectAttribute.cs | 0 .../Core/Binary}/BinaryAttribute.cs | 0 .../Core/Boolean}/BooleanAttribute.cs | 0 .../Core/Date}/DateAttribute.cs | 0 .../Core/Number}/NumberAttribute.cs | 0 .../Core/String}/StringAttribute.cs | 0 .../Geo/GeoPoint}/GeoPointAttribute.cs | 0 .../Geo/GeoShape}/GeoShapeAttribute.cs | 0 .../Attachment}/AttachmentAttribute.cs | 0 .../Completion}/CompletionAttribute.cs | 0 .../Specialized/Ip}/IpAttribute.cs | 0 .../Murmur3Hash}/Murmur3HashAttribute.cs | 0 .../TokenCount}/TokenCountAttribute.cs | 0 src/Nest/Nest.csproj | 30 +++++++++---------- 16 files changed, 15 insertions(+), 15 deletions(-) rename src/Nest/Mapping/{CodeBased => }/PropertyMapping.cs (100%) rename src/Nest/Mapping/{AttributeBased => Types/Complex/Nested}/NestedAttribute.cs (100%) rename src/Nest/Mapping/{AttributeBased => Types/Complex/Object}/ObjectAttribute.cs (100%) rename src/Nest/Mapping/{AttributeBased => Types/Core/Binary}/BinaryAttribute.cs (100%) rename src/Nest/Mapping/{AttributeBased => Types/Core/Boolean}/BooleanAttribute.cs (100%) rename src/Nest/Mapping/{AttributeBased => Types/Core/Date}/DateAttribute.cs (100%) rename src/Nest/Mapping/{AttributeBased => Types/Core/Number}/NumberAttribute.cs (100%) rename src/Nest/Mapping/{AttributeBased => Types/Core/String}/StringAttribute.cs (100%) rename src/Nest/Mapping/{AttributeBased => Types/Geo/GeoPoint}/GeoPointAttribute.cs (100%) rename src/Nest/Mapping/{AttributeBased => Types/Geo/GeoShape}/GeoShapeAttribute.cs (100%) rename src/Nest/Mapping/{AttributeBased => Types/Specialized/Attachment}/AttachmentAttribute.cs (100%) rename src/Nest/Mapping/{AttributeBased => Types/Specialized/Completion}/CompletionAttribute.cs (100%) rename src/Nest/Mapping/{AttributeBased => Types/Specialized/Ip}/IpAttribute.cs (100%) rename src/Nest/Mapping/{AttributeBased => Types/Specialized/Murmur3Hash}/Murmur3HashAttribute.cs (100%) rename src/Nest/Mapping/{AttributeBased => Types/Specialized/TokenCount}/TokenCountAttribute.cs (100%) diff --git a/src/Nest/Mapping/CodeBased/PropertyMapping.cs b/src/Nest/Mapping/PropertyMapping.cs similarity index 100% rename from src/Nest/Mapping/CodeBased/PropertyMapping.cs rename to src/Nest/Mapping/PropertyMapping.cs diff --git a/src/Nest/Mapping/AttributeBased/NestedAttribute.cs b/src/Nest/Mapping/Types/Complex/Nested/NestedAttribute.cs similarity index 100% rename from src/Nest/Mapping/AttributeBased/NestedAttribute.cs rename to src/Nest/Mapping/Types/Complex/Nested/NestedAttribute.cs diff --git a/src/Nest/Mapping/AttributeBased/ObjectAttribute.cs b/src/Nest/Mapping/Types/Complex/Object/ObjectAttribute.cs similarity index 100% rename from src/Nest/Mapping/AttributeBased/ObjectAttribute.cs rename to src/Nest/Mapping/Types/Complex/Object/ObjectAttribute.cs diff --git a/src/Nest/Mapping/AttributeBased/BinaryAttribute.cs b/src/Nest/Mapping/Types/Core/Binary/BinaryAttribute.cs similarity index 100% rename from src/Nest/Mapping/AttributeBased/BinaryAttribute.cs rename to src/Nest/Mapping/Types/Core/Binary/BinaryAttribute.cs diff --git a/src/Nest/Mapping/AttributeBased/BooleanAttribute.cs b/src/Nest/Mapping/Types/Core/Boolean/BooleanAttribute.cs similarity index 100% rename from src/Nest/Mapping/AttributeBased/BooleanAttribute.cs rename to src/Nest/Mapping/Types/Core/Boolean/BooleanAttribute.cs diff --git a/src/Nest/Mapping/AttributeBased/DateAttribute.cs b/src/Nest/Mapping/Types/Core/Date/DateAttribute.cs similarity index 100% rename from src/Nest/Mapping/AttributeBased/DateAttribute.cs rename to src/Nest/Mapping/Types/Core/Date/DateAttribute.cs diff --git a/src/Nest/Mapping/AttributeBased/NumberAttribute.cs b/src/Nest/Mapping/Types/Core/Number/NumberAttribute.cs similarity index 100% rename from src/Nest/Mapping/AttributeBased/NumberAttribute.cs rename to src/Nest/Mapping/Types/Core/Number/NumberAttribute.cs diff --git a/src/Nest/Mapping/AttributeBased/StringAttribute.cs b/src/Nest/Mapping/Types/Core/String/StringAttribute.cs similarity index 100% rename from src/Nest/Mapping/AttributeBased/StringAttribute.cs rename to src/Nest/Mapping/Types/Core/String/StringAttribute.cs diff --git a/src/Nest/Mapping/AttributeBased/GeoPointAttribute.cs b/src/Nest/Mapping/Types/Geo/GeoPoint/GeoPointAttribute.cs similarity index 100% rename from src/Nest/Mapping/AttributeBased/GeoPointAttribute.cs rename to src/Nest/Mapping/Types/Geo/GeoPoint/GeoPointAttribute.cs diff --git a/src/Nest/Mapping/AttributeBased/GeoShapeAttribute.cs b/src/Nest/Mapping/Types/Geo/GeoShape/GeoShapeAttribute.cs similarity index 100% rename from src/Nest/Mapping/AttributeBased/GeoShapeAttribute.cs rename to src/Nest/Mapping/Types/Geo/GeoShape/GeoShapeAttribute.cs diff --git a/src/Nest/Mapping/AttributeBased/AttachmentAttribute.cs b/src/Nest/Mapping/Types/Specialized/Attachment/AttachmentAttribute.cs similarity index 100% rename from src/Nest/Mapping/AttributeBased/AttachmentAttribute.cs rename to src/Nest/Mapping/Types/Specialized/Attachment/AttachmentAttribute.cs diff --git a/src/Nest/Mapping/AttributeBased/CompletionAttribute.cs b/src/Nest/Mapping/Types/Specialized/Completion/CompletionAttribute.cs similarity index 100% rename from src/Nest/Mapping/AttributeBased/CompletionAttribute.cs rename to src/Nest/Mapping/Types/Specialized/Completion/CompletionAttribute.cs diff --git a/src/Nest/Mapping/AttributeBased/IpAttribute.cs b/src/Nest/Mapping/Types/Specialized/Ip/IpAttribute.cs similarity index 100% rename from src/Nest/Mapping/AttributeBased/IpAttribute.cs rename to src/Nest/Mapping/Types/Specialized/Ip/IpAttribute.cs diff --git a/src/Nest/Mapping/AttributeBased/Murmur3HashAttribute.cs b/src/Nest/Mapping/Types/Specialized/Murmur3Hash/Murmur3HashAttribute.cs similarity index 100% rename from src/Nest/Mapping/AttributeBased/Murmur3HashAttribute.cs rename to src/Nest/Mapping/Types/Specialized/Murmur3Hash/Murmur3HashAttribute.cs diff --git a/src/Nest/Mapping/AttributeBased/TokenCountAttribute.cs b/src/Nest/Mapping/Types/Specialized/TokenCount/TokenCountAttribute.cs similarity index 100% rename from src/Nest/Mapping/AttributeBased/TokenCountAttribute.cs rename to src/Nest/Mapping/Types/Specialized/TokenCount/TokenCountAttribute.cs diff --git a/src/Nest/Nest.csproj b/src/Nest/Nest.csproj index 524db43d06c..cb9a9cc91aa 100644 --- a/src/Nest/Nest.csproj +++ b/src/Nest/Nest.csproj @@ -272,22 +272,22 @@ - - - - - + + + + + - - - - - - - - - + + + + + + + + + @@ -476,7 +476,7 @@ - +