Skip to content

Commit a8b121b

Browse files
committed
Implement descriptor for norms and renamed from NormsMapping => Norms
Relates #1723
1 parent 8454c4a commit a8b121b

File tree

8 files changed

+78
-26
lines changed

8 files changed

+78
-26
lines changed

src/Nest/Mapping/AttributeBased/StringAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class StringAttribute : ElasticsearchPropertyAttribute, IStringProperty
88
TermVectorOption? IStringProperty.TermVector { get; set; }
99
double? IStringProperty.Boost { get; set; }
1010
string IStringProperty.NullValue { get; set; }
11-
NormsMapping IStringProperty.Norms { get; set; }
11+
INorms IStringProperty.Norms { get; set; }
1212
IndexOptions? IStringProperty.IndexOptions { get; set; }
1313
string IStringProperty.Analyzer { get; set; }
1414
string IStringProperty.SearchAnalyzer { get; set; }

src/Nest/Mapping/Norms/Norms.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System;
2+
using Newtonsoft.Json;
3+
using Newtonsoft.Json.Converters;
4+
5+
namespace Nest
6+
{
7+
[JsonObject(MemberSerialization.OptIn)]
8+
[JsonConverter(typeof(ReadAsTypeJsonConverter<Norms>))]
9+
public interface INorms
10+
{
11+
[JsonProperty("enabled")]
12+
bool? Enabled { get; set; }
13+
14+
[JsonProperty("loading")]
15+
[JsonConverter(typeof(StringEnumConverter))]
16+
NormsLoading? Loading { get; set; }
17+
}
18+
19+
public class Norms : INorms
20+
{
21+
public bool? Enabled { get; set; }
22+
public NormsLoading? Loading { get; set; }
23+
}
24+
25+
public class NormsDescriptor : DescriptorBase<NormsDescriptor, INorms>, INorms
26+
{
27+
bool? INorms.Enabled { get; set; }
28+
NormsLoading? INorms.Loading { get; set; }
29+
30+
public NormsDescriptor Enabled(bool enabled = true) => Assign(a => a.Enabled = enabled);
31+
public NormsDescriptor Loading(NormsLoading loading) => Assign(a => a.Loading = loading);
32+
}
33+
}

src/Nest/Mapping/Norms/NormsMapping.cs

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/Nest/Mapping/Types/Core/String/StringProperty.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public interface IStringProperty : IProperty
1919
string NullValue { get; set; }
2020

2121
[JsonProperty("norms")]
22-
NormsMapping Norms { get; set; }
22+
INorms Norms { get; set; }
2323

2424
[JsonProperty("index_options")]
2525
IndexOptions? IndexOptions { get; set; }
@@ -51,7 +51,7 @@ public StringProperty() : base("string") { }
5151
public TermVectorOption? TermVector { get; set; }
5252
public double? Boost { get; set; }
5353
public string NullValue { get; set; }
54-
public NormsMapping Norms { get; set; }
54+
public INorms Norms { get; set; }
5555
public IndexOptions? IndexOptions { get; set; }
5656
public string Analyzer { get; set; }
5757
public string SearchAnalyzer { get; set; }
@@ -69,7 +69,7 @@ public class StringPropertyDescriptor<T>
6969
TermVectorOption? IStringProperty.TermVector { get; set; }
7070
double? IStringProperty.Boost { get; set; }
7171
string IStringProperty.NullValue { get; set; }
72-
NormsMapping IStringProperty.Norms { get; set; }
72+
INorms IStringProperty.Norms { get; set; }
7373
IndexOptions? IStringProperty.IndexOptions { get; set; }
7474
string IStringProperty.Analyzer { get; set; }
7575
string IStringProperty.SearchAnalyzer { get; set; }
@@ -99,7 +99,7 @@ public StringPropertyDescriptor() : base("string") { }
9999

100100
public StringPropertyDescriptor<T> SearchAnalyzer(string searchAnalyzer) => Assign(a => a.SearchAnalyzer = searchAnalyzer);
101101

102-
public StringPropertyDescriptor<T> Norms(NormsMapping normsMapping) => Assign(a => a.Norms = normsMapping);
102+
public StringPropertyDescriptor<T> Norms(Func<NormsDescriptor, INorms> selector) => Assign(a => a.Norms = selector?.Invoke(new NormsDescriptor()));
103103

104104
public StringPropertyDescriptor<T> IgnoreAbove(int ignoreAbove) => Assign(a => a.IgnoreAbove = ignoreAbove);
105105

@@ -108,6 +108,6 @@ public StringPropertyDescriptor() : base("string") { }
108108
public StringPropertyDescriptor<T> PositionOffsetGap(int positionOffsetGap) => Assign(a => a.PositionOffsetGap = positionOffsetGap);
109109

110110
public StringPropertyDescriptor<T> Fielddata(Func<StringFielddataDescriptor, IStringFielddata> selector) =>
111-
Assign(a => selector(new StringFielddataDescriptor()));
111+
Assign(a => a.Fielddata = selector?.Invoke(new StringFielddataDescriptor()));
112112
}
113113
}

src/Nest/Nest.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@
509509
<Compile Include="QueryDsl\Geo\Shape\Polygon\PolygonGeoShape.cs" />
510510
<Compile Include="Mapping\MetaFields\FieldNames\FieldNamesField.cs" />
511511
<Compile Include="Modules\Indices\Fielddata\FielddataBase.cs" />
512-
<Compile Include="Mapping\Norms\NormsMapping.cs" />
512+
<Compile Include="Mapping\Norms\Norms.cs" />
513513
<Compile Include="Document\Multiple\DeleteByQuery\DeleteByQueryResponse.cs" />
514514
<Compile Include="Mapping\Transform\MappingTransform.cs" />
515515
<Compile Include="Mapping\Types\Specialized\Murmur3Hash\Murmur3HashProperty.cs" />

src/Tests/Mapping/Types/Core/String/StringMappingTests.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,5 +102,29 @@ public class StringMappingTests : TypeMappingTestBase<StringTest>
102102
.String(s => s
103103
.Name(o => o.Guid)
104104
);
105+
106+
protected override object ExpectJsonFluentOnly => new
107+
{
108+
properties = new
109+
{
110+
full = new
111+
{
112+
type = "string",
113+
norms = new
114+
{
115+
enabled = true,
116+
loading = "lazy"
117+
}
118+
}
119+
}
120+
};
121+
protected override Func<PropertiesDescriptor<StringTest>, IPromise<IProperties>> FluentOnlyProperties => p => p
122+
.String(s => s
123+
.Name(o => o.Full)
124+
.Norms(n => n
125+
.Enabled()
126+
.Loading(NormsLoading.Lazy)
127+
)
128+
);
105129
}
106130
}

src/Tests/Mapping/Types/TypeMappingTestBase.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,28 @@ public abstract class TypeMappingTestBase<T>
1010
{
1111
protected abstract object ExpectJson { get; }
1212

13+
protected virtual object ExpectJsonFluentOnly { get; }
14+
1315
protected abstract Func<PropertiesDescriptor<T>, IPromise<IProperties>> FluentProperties { get; }
1416

17+
protected virtual Func<PropertiesDescriptor<T>, IPromise<IProperties>> FluentOnlyProperties { get; }
18+
1519
[U]
1620
protected virtual void AttributeBasedSerializes() =>
1721
Expect(ExpectJson)
1822
.WhenSerializing(new PutMappingDescriptor<T>().AutoMap() as IPutMappingRequest);
1923

2024
[U]
21-
protected virtual void CodeBasedSerializes() =>
25+
protected virtual void CodeBasedSerializes()
26+
{
2227
Expect(ExpectJson)
2328
.WhenSerializing(new PutMappingDescriptor<T>().Properties(FluentProperties) as IPutMappingRequest);
29+
30+
if (ExpectJsonFluentOnly != null)
31+
{
32+
Expect(ExpectJsonFluentOnly)
33+
.WhenSerializing(new PutMappingDescriptor<T>().Properties(FluentOnlyProperties) as IPutMappingRequest);
34+
}
35+
}
2436
}
2537
}

src/Tests/tests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# mode either u (unit test), i (integration test) or m (mixed mode)
2-
mode: i
2+
mode: u
33
# the elasticsearch version that should be started
44
elasticsearch_version: 2.0.1
55
# whether we want to forcefully reseed on the node, if you are starting the tests with a node already running

0 commit comments

Comments
 (0)