Skip to content

Commit 48a2200

Browse files
committed
Mark PositionOffsetGap as obsolete in favor of PositionIncrementGap
Closes #2027
1 parent 8b71b98 commit 48a2200

File tree

3 files changed

+32
-13
lines changed

3 files changed

+32
-13
lines changed

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace Nest
1+
using System;
2+
3+
namespace Nest
24
{
35
public class StringAttribute : ElasticsearchPropertyAttributeBase, IStringProperty
46
{
@@ -14,7 +16,9 @@ public class StringAttribute : ElasticsearchPropertyAttributeBase, IStringProper
1416
string IStringProperty.SearchAnalyzer { get; set; }
1517
bool? IStringProperty.IncludeInAll { get; set; }
1618
int? IStringProperty.IgnoreAbove { get; set; }
17-
int? IStringProperty.PositionOffsetGap { get; set; }
19+
[Obsolete("Scheduled to be removed in 5.0. Use PositionIncrementGap instead.")]
20+
int? IStringProperty.PositionOffsetGap { get { return Self.PositionIncrementGap; } set { Self.PositionIncrementGap = value; } }
21+
int? IStringProperty.PositionIncrementGap { get; set; }
1822
IStringFielddata IStringProperty.Fielddata { get; set; }
1923

2024
public string Analyzer { get { return Self.Analyzer; } set { Self.Analyzer = value; } }
@@ -24,7 +28,9 @@ public class StringAttribute : ElasticsearchPropertyAttributeBase, IStringProper
2428
public FieldIndexOption Index { get { return Self.Index.GetValueOrDefault(); } set { Self.Index = value; } }
2529
public IndexOptions IndexOptions { get { return Self.IndexOptions.GetValueOrDefault(); } set { Self.IndexOptions = value; } }
2630
public string NullValue { get { return Self.NullValue; } set { Self.NullValue = value; } }
27-
public int PositionOffsetGap { get { return Self.PositionOffsetGap.GetValueOrDefault(); } set { Self.PositionOffsetGap = value; } }
31+
[Obsolete("Scheduled to be removed in 5.0. Use PositionIncrementGap instead.")]
32+
public int PositionOffsetGap { get { return Self.PositionIncrementGap.GetValueOrDefault(); } set { Self.PositionIncrementGap = value; } }
33+
public int PositionIncrementGap { get { return Self.PositionIncrementGap.GetValueOrDefault(); } set { Self.PositionIncrementGap = value; } }
2834
public string SearchAnalyzer { get { return Self.SearchAnalyzer; } set { Self.SearchAnalyzer = value; } }
2935
public TermVectorOption TermVector { get { return Self.TermVector.GetValueOrDefault(); } set { Self.TermVector = value; } }
3036

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

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,13 @@ public interface IStringProperty : IProperty
3636
[JsonProperty("ignore_above")]
3737
int? IgnoreAbove { get; set; }
3838

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

43+
[JsonProperty("position_increment_gap")]
44+
int? PositionIncrementGap { get; set; }
45+
4246
[JsonProperty("fielddata")]
4347
IStringFielddata Fielddata { get; set; }
4448
}
@@ -57,11 +61,14 @@ public StringProperty() : base("string") { }
5761
public string SearchAnalyzer { get; set; }
5862
public bool? IncludeInAll { get; set; }
5963
public int? IgnoreAbove { get; set; }
60-
public int? PositionOffsetGap { get; set; }
64+
[Obsolete("Scheduled to be removed in 5.0. Use PositionIncrementGap instead.")]
65+
public int? PositionOffsetGap { get { return PositionIncrementGap; } set { PositionIncrementGap = value; } }
66+
public int? PositionIncrementGap { get; set; }
6167
public IStringFielddata Fielddata { get; set; }
68+
6269
}
6370

64-
public class StringPropertyDescriptor<T>
71+
public class StringPropertyDescriptor<T>
6572
: PropertyDescriptorBase<StringPropertyDescriptor<T>, IStringProperty, T>, IStringProperty
6673
where T : class
6774
{
@@ -75,7 +82,9 @@ public class StringPropertyDescriptor<T>
7582
string IStringProperty.SearchAnalyzer { get; set; }
7683
bool? IStringProperty.IncludeInAll { get; set; }
7784
int? IStringProperty.IgnoreAbove { get; set; }
78-
int? IStringProperty.PositionOffsetGap { get; set; }
85+
[Obsolete("Scheduled to be removed in 5.0. Use PositionIncrementGap instead.")]
86+
int? IStringProperty.PositionOffsetGap { get { return Self.PositionIncrementGap; } set { Self.PositionIncrementGap = value; } }
87+
int? IStringProperty.PositionIncrementGap { get; set; }
7988
IStringFielddata IStringProperty.Fielddata { get; set; }
8089

8190
public StringPropertyDescriptor() : base("string") { }
@@ -105,9 +114,12 @@ public StringPropertyDescriptor() : base("string") { }
105114

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

108-
public StringPropertyDescriptor<T> PositionOffsetGap(int positionOffsetGap) => Assign(a => a.PositionOffsetGap = positionOffsetGap);
117+
[Obsolete("Scheduled to be removed in 5.0. Use PositionIncrementGap() instead.")]
118+
public StringPropertyDescriptor<T> PositionOffsetGap(int positionOffsetGap) => Assign(a => a.PositionIncrementGap = positionOffsetGap);
119+
120+
public StringPropertyDescriptor<T> PositionIncrementGap(int? positionIncrementGap) => Assign(a => a.PositionIncrementGap = positionIncrementGap);
109121

110122
public StringPropertyDescriptor<T> Fielddata(Func<StringFielddataDescriptor, IStringFielddata> selector) =>
111123
Assign(a => a.Fielddata = selector?.Invoke(new StringFielddataDescriptor()));
112124
}
113-
}
125+
}

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public class StringTest
1414
Index = FieldIndexOption.NotAnalyzed,
1515
IndexOptions = IndexOptions.Offsets,
1616
NullValue = "na",
17+
// Purposely setting this obsolete property to ensure it serializes as position_increment_gap
1718
PositionOffsetGap = 5,
1819
SearchAnalyzer = "mysearchanalyzer",
1920
Similarity = SimilarityOption.BM25,
@@ -48,7 +49,7 @@ public class StringMappingTests : TypeMappingTestBase<StringTest>
4849
index = "not_analyzed",
4950
index_options = "offsets",
5051
null_value = "na",
51-
position_offset_gap = 5,
52+
position_increment_gap = 5,
5253
search_analyzer = "mysearchanalyzer",
5354
similarity = "BM25",
5455
store = true,
@@ -57,11 +58,11 @@ public class StringMappingTests : TypeMappingTestBase<StringTest>
5758
minimal = new
5859
{
5960
type = "string"
60-
},
61+
},
6162
inferred = new
6263
{
6364
type = "string"
64-
},
65+
},
6566
@char = new
6667
{
6768
type = "string"
@@ -84,7 +85,7 @@ public class StringMappingTests : TypeMappingTestBase<StringTest>
8485
.Index(FieldIndexOption.NotAnalyzed)
8586
.IndexOptions(IndexOptions.Offsets)
8687
.NullValue("na")
87-
.PositionOffsetGap(5)
88+
.PositionIncrementGap(5)
8889
.SearchAnalyzer("mysearchanalyzer")
8990
.Similarity(SimilarityOption.BM25)
9091
.Store(true)

0 commit comments

Comments
 (0)