Skip to content

Mark PositionOffsetGap as obsolete in favor of PositionIncrementGap #2029

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 1 commit into from
Apr 12, 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
12 changes: 9 additions & 3 deletions src/Nest/Mapping/Types/Core/String/StringAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace Nest
using System;

namespace Nest
{
public class StringAttribute : ElasticsearchPropertyAttributeBase, IStringProperty
{
Expand All @@ -14,7 +16,9 @@ public class StringAttribute : ElasticsearchPropertyAttributeBase, IStringProper
string IStringProperty.SearchAnalyzer { get; set; }
bool? IStringProperty.IncludeInAll { get; set; }
int? IStringProperty.IgnoreAbove { get; set; }
int? IStringProperty.PositionOffsetGap { get; set; }
[Obsolete("Scheduled to be removed in 5.0. Use PositionIncrementGap instead.")]
int? IStringProperty.PositionOffsetGap { get { return Self.PositionIncrementGap; } set { Self.PositionIncrementGap = value; } }
int? IStringProperty.PositionIncrementGap { get; set; }
IStringFielddata IStringProperty.Fielddata { get; set; }

public string Analyzer { get { return Self.Analyzer; } set { Self.Analyzer = value; } }
Expand All @@ -24,7 +28,9 @@ public class StringAttribute : ElasticsearchPropertyAttributeBase, IStringProper
public FieldIndexOption Index { get { return Self.Index.GetValueOrDefault(); } set { Self.Index = value; } }
public IndexOptions IndexOptions { get { return Self.IndexOptions.GetValueOrDefault(); } set { Self.IndexOptions = value; } }
public string NullValue { get { return Self.NullValue; } set { Self.NullValue = value; } }
public int PositionOffsetGap { get { return Self.PositionOffsetGap.GetValueOrDefault(); } set { Self.PositionOffsetGap = value; } }
[Obsolete("Scheduled to be removed in 5.0. Use PositionIncrementGap instead.")]
public int PositionOffsetGap { get { return Self.PositionIncrementGap.GetValueOrDefault(); } set { Self.PositionIncrementGap = value; } }
public int PositionIncrementGap { get { return Self.PositionIncrementGap.GetValueOrDefault(); } set { Self.PositionIncrementGap = value; } }
public string SearchAnalyzer { get { return Self.SearchAnalyzer; } set { Self.SearchAnalyzer = value; } }
public TermVectorOption TermVector { get { return Self.TermVector.GetValueOrDefault(); } set { Self.TermVector = value; } }

Expand Down
24 changes: 18 additions & 6 deletions src/Nest/Mapping/Types/Core/String/StringProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,13 @@ public interface IStringProperty : IProperty
[JsonProperty("ignore_above")]
int? IgnoreAbove { get; set; }

[JsonProperty("position_offset_gap")]
[JsonIgnore]
[Obsolete("Scheduled to be removed in 5.0. Use PositionIncrementGap instead.")]
int? PositionOffsetGap { get; set; }

[JsonProperty("position_increment_gap")]
int? PositionIncrementGap { get; set; }

[JsonProperty("fielddata")]
IStringFielddata Fielddata { get; set; }
}
Expand All @@ -57,11 +61,14 @@ public StringProperty() : base("string") { }
public string SearchAnalyzer { get; set; }
public bool? IncludeInAll { get; set; }
public int? IgnoreAbove { get; set; }
public int? PositionOffsetGap { get; set; }
[Obsolete("Scheduled to be removed in 5.0. Use PositionIncrementGap instead.")]
public int? PositionOffsetGap { get { return PositionIncrementGap; } set { PositionIncrementGap = value; } }
public int? PositionIncrementGap { get; set; }
public IStringFielddata Fielddata { get; set; }

}

public class StringPropertyDescriptor<T>
public class StringPropertyDescriptor<T>
: PropertyDescriptorBase<StringPropertyDescriptor<T>, IStringProperty, T>, IStringProperty
where T : class
{
Expand All @@ -75,7 +82,9 @@ public class StringPropertyDescriptor<T>
string IStringProperty.SearchAnalyzer { get; set; }
bool? IStringProperty.IncludeInAll { get; set; }
int? IStringProperty.IgnoreAbove { get; set; }
int? IStringProperty.PositionOffsetGap { get; set; }
[Obsolete("Scheduled to be removed in 5.0. Use PositionIncrementGap instead.")]
int? IStringProperty.PositionOffsetGap { get { return Self.PositionIncrementGap; } set { Self.PositionIncrementGap = value; } }
int? IStringProperty.PositionIncrementGap { get; set; }
IStringFielddata IStringProperty.Fielddata { get; set; }

public StringPropertyDescriptor() : base("string") { }
Expand Down Expand Up @@ -105,9 +114,12 @@ public StringPropertyDescriptor() : base("string") { }

public StringPropertyDescriptor<T> IncludeInAll(bool includeInAll = true) => Assign(a => a.IncludeInAll = includeInAll);

public StringPropertyDescriptor<T> PositionOffsetGap(int positionOffsetGap) => Assign(a => a.PositionOffsetGap = positionOffsetGap);
[Obsolete("Scheduled to be removed in 5.0. Use PositionIncrementGap() instead.")]
public StringPropertyDescriptor<T> PositionOffsetGap(int positionOffsetGap) => Assign(a => a.PositionIncrementGap = positionOffsetGap);

public StringPropertyDescriptor<T> PositionIncrementGap(int? positionIncrementGap) => Assign(a => a.PositionIncrementGap = positionIncrementGap);

public StringPropertyDescriptor<T> Fielddata(Func<StringFielddataDescriptor, IStringFielddata> selector) =>
Assign(a => a.Fielddata = selector?.Invoke(new StringFielddataDescriptor()));
}
}
}
9 changes: 5 additions & 4 deletions src/Tests/Mapping/Types/Core/String/StringMappingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class StringTest
Index = FieldIndexOption.NotAnalyzed,
IndexOptions = IndexOptions.Offsets,
NullValue = "na",
// Purposely setting this obsolete property to ensure it serializes as position_increment_gap
PositionOffsetGap = 5,
SearchAnalyzer = "mysearchanalyzer",
Similarity = SimilarityOption.BM25,
Expand Down Expand Up @@ -48,7 +49,7 @@ public class StringMappingTests : TypeMappingTestBase<StringTest>
index = "not_analyzed",
index_options = "offsets",
null_value = "na",
position_offset_gap = 5,
position_increment_gap = 5,
search_analyzer = "mysearchanalyzer",
similarity = "BM25",
store = true,
Expand All @@ -57,11 +58,11 @@ public class StringMappingTests : TypeMappingTestBase<StringTest>
minimal = new
{
type = "string"
},
},
inferred = new
{
type = "string"
},
},
@char = new
{
type = "string"
Expand All @@ -84,7 +85,7 @@ public class StringMappingTests : TypeMappingTestBase<StringTest>
.Index(FieldIndexOption.NotAnalyzed)
.IndexOptions(IndexOptions.Offsets)
.NullValue("na")
.PositionOffsetGap(5)
.PositionIncrementGap(5)
.SearchAnalyzer("mysearchanalyzer")
.Similarity(SimilarityOption.BM25)
.Store(true)
Expand Down