Skip to content

Fix/norms mapping #1726

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions src/Nest/Mapping/Norms/Norms.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace Nest
{
[JsonObject(MemberSerialization.OptIn)]
[JsonConverter(typeof(ReadAsTypeJsonConverter<Norms>))]
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<NormsDescriptor, INorms>, 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);
}
}
17 changes: 0 additions & 17 deletions src/Nest/Mapping/Norms/NormsMapping.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
10 changes: 5 additions & 5 deletions src/Nest/Mapping/Types/Core/String/StringProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down Expand Up @@ -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; }
Expand All @@ -69,7 +69,7 @@ public class StringPropertyDescriptor<T>
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; }
Expand Down Expand Up @@ -99,7 +99,7 @@ public StringPropertyDescriptor() : base("string") { }

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

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

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

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

public StringPropertyDescriptor<T> Fielddata(Func<StringFielddataDescriptor, IStringFielddata> selector) =>
Assign(a => selector(new StringFielddataDescriptor()));
Assign(a => a.Fielddata = selector?.Invoke(new StringFielddataDescriptor()));
}
}
32 changes: 16 additions & 16 deletions src/Nest/Nest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -272,22 +272,22 @@
<Compile Include="Indices\Warmers\PutWarmer\PutWarmerRequestJsonConverter.cs" />
<Compile Include="Indices\Warmers\PutWarmer\PutWarmerResponse.cs" />
<Compile Include="Indices\Warmers\Warmers.cs" />
<Compile Include="Mapping\AttributeBased\AttachmentAttribute.cs" />
<Compile Include="Mapping\AttributeBased\BinaryAttribute.cs" />
<Compile Include="Mapping\AttributeBased\BooleanAttribute.cs" />
<Compile Include="Mapping\AttributeBased\CompletionAttribute.cs" />
<Compile Include="Mapping\AttributeBased\DateAttribute.cs" />
<Compile Include="Mapping\Types\Specialized\Attachment\AttachmentAttribute.cs" />
<Compile Include="Mapping\Types\Core\Binary\BinaryAttribute.cs" />
<Compile Include="Mapping\Types\Core\Boolean\BooleanAttribute.cs" />
<Compile Include="Mapping\Types\Specialized\Completion\CompletionAttribute.cs" />
<Compile Include="Mapping\Types\Core\Date\DateAttribute.cs" />
<Compile Include="Mapping\AttributeBased\ElasticsearchPropertyAttribute.cs" />
<Compile Include="Mapping\AttributeBased\ElasticsearchTypeAttribute.cs" />
<Compile Include="Mapping\AttributeBased\GeoPointAttribute.cs" />
<Compile Include="Mapping\AttributeBased\GeoShapeAttribute.cs" />
<Compile Include="Mapping\AttributeBased\IpAttribute.cs" />
<Compile Include="Mapping\AttributeBased\Murmur3HashAttribute.cs" />
<Compile Include="Mapping\AttributeBased\NestedAttribute.cs" />
<Compile Include="Mapping\AttributeBased\NumberAttribute.cs" />
<Compile Include="Mapping\AttributeBased\ObjectAttribute.cs" />
<Compile Include="Mapping\AttributeBased\StringAttribute.cs" />
<Compile Include="Mapping\AttributeBased\TokenCountAttribute.cs" />
<Compile Include="Mapping\Types\Geo\GeoPoint\GeoPointAttribute.cs" />
<Compile Include="Mapping\Types\Geo\GeoShape\GeoShapeAttribute.cs" />
<Compile Include="Mapping\Types\Specialized\Ip\IpAttribute.cs" />
<Compile Include="Mapping\Types\Specialized\Murmur3Hash\Murmur3HashAttribute.cs" />
<Compile Include="Mapping\Types\Complex\Nested\NestedAttribute.cs" />
<Compile Include="Mapping\Types\Core\Number\NumberAttribute.cs" />
<Compile Include="Mapping\Types\Complex\Object\ObjectAttribute.cs" />
<Compile Include="Mapping\Types\Core\String\StringAttribute.cs" />
<Compile Include="Mapping\Types\Specialized\TokenCount\TokenCountAttribute.cs" />
<Compile Include="Indices\MappingManagement\GetFieldMapping\FieldMappingJsonConverter.cs" />
<Compile Include="Mapping\DynamicTemplate\DynamicTemplateContainer.cs" />
<Compile Include="Mapping\DynamicTemplate\DynamicTemplatesJsonConverter.cs" />
Expand Down Expand Up @@ -476,7 +476,7 @@
<Compile Include="CommonAbstractions\LazyDocument\LazyDocument.cs" />
<Compile Include="QueryDsl\Geo\GeoLocation.cs" />
<Compile Include="Search\Explain\ExplainGet.cs" />
<Compile Include="Mapping\CodeBased\PropertyMapping.cs" />
<Compile Include="Mapping\PropertyMapping.cs" />
<Compile Include="Modules\Indices\Fielddata\FielddataFilter.cs" />
<Compile Include="Modules\Indices\Fielddata\FielddataFrequencyFilter.cs" />
<Compile Include="Modules\Indices\Fielddata\FielddataRegexFilter.cs" />
Expand Down Expand Up @@ -509,7 +509,7 @@
<Compile Include="QueryDsl\Geo\Shape\Polygon\PolygonGeoShape.cs" />
<Compile Include="Mapping\MetaFields\FieldNames\FieldNamesField.cs" />
<Compile Include="Modules\Indices\Fielddata\FielddataBase.cs" />
<Compile Include="Mapping\Norms\NormsMapping.cs" />
<Compile Include="Mapping\Norms\Norms.cs" />
<Compile Include="Document\Multiple\DeleteByQuery\DeleteByQueryResponse.cs" />
<Compile Include="Mapping\Transform\MappingTransform.cs" />
<Compile Include="Mapping\Types\Specialized\Murmur3Hash\Murmur3HashProperty.cs" />
Expand Down
24 changes: 24 additions & 0 deletions src/Tests/Mapping/Types/Core/String/StringMappingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,29 @@ public class StringMappingTests : TypeMappingTestBase<StringTest>
.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<PropertiesDescriptor<StringTest>, IPromise<IProperties>> FluentOnlyProperties => p => p
.String(s => s
.Name(o => o.Full)
.Norms(n => n
.Enabled()
.Loading(NormsLoading.Lazy)
)
);
}
}
14 changes: 13 additions & 1 deletion src/Tests/Mapping/Types/TypeMappingTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,28 @@ public abstract class TypeMappingTestBase<T>
{
protected abstract object ExpectJson { get; }

protected virtual object ExpectJsonFluentOnly { get; }

protected abstract Func<PropertiesDescriptor<T>, IPromise<IProperties>> FluentProperties { get; }

protected virtual Func<PropertiesDescriptor<T>, IPromise<IProperties>> FluentOnlyProperties { get; }

[U]
protected virtual void AttributeBasedSerializes() =>
Expect(ExpectJson)
.WhenSerializing(new PutMappingDescriptor<T>().AutoMap() as IPutMappingRequest);

[U]
protected virtual void CodeBasedSerializes() =>
protected virtual void CodeBasedSerializes()
{
Expect(ExpectJson)
.WhenSerializing(new PutMappingDescriptor<T>().Properties(FluentProperties) as IPutMappingRequest);

if (ExpectJsonFluentOnly != null)
{
Expect(ExpectJsonFluentOnly)
.WhenSerializing(new PutMappingDescriptor<T>().Properties(FluentOnlyProperties) as IPutMappingRequest);
}
}
}
}
2 changes: 1 addition & 1 deletion src/Tests/tests.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down