Skip to content

Commit f78d25d

Browse files
stevejgordonrdasan
andauthored
Add support for enable_position_increments property on ITokenCountProperty (#5188) (#5197)
* adding support for enable_position_increments property on ITokenCountProperty and ITokenCountPropertyDescriptor * Update src/Nest/Mapping/Types/Specialized/TokenCount/TokenCountAttribute.cs Co-authored-by: Russ Cam <[email protected]> (cherry picked from commit 70f9b5d) Co-authored-by: Reji Dasan <[email protected]>
1 parent 306c4be commit f78d25d

File tree

4 files changed

+20
-5
lines changed

4 files changed

+20
-5
lines changed

src/Nest/Mapping/Types/Specialized/TokenCount/TokenCountAttribute.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ public double Boost
2222
#pragma warning restore 618
2323
}
2424

25+
public bool EnablePositionIncrements
26+
{
27+
get => Self.EnablePositionIncrements.GetValueOrDefault(true);
28+
set => Self.EnablePositionIncrements = value;
29+
}
30+
2531
public bool Index
2632
{
2733
get => Self.Index.GetValueOrDefault();
@@ -36,6 +42,7 @@ public double NullValue
3642

3743
string ITokenCountProperty.Analyzer { get; set; }
3844
double? ITokenCountProperty.Boost { get; set; }
45+
bool? ITokenCountProperty.EnablePositionIncrements { get; set; }
3946
bool? ITokenCountProperty.Index { get; set; }
4047
double? ITokenCountProperty.NullValue { get; set; }
4148
private ITokenCountProperty Self => this;

src/Nest/Mapping/Types/Specialized/TokenCount/TokenCountProperty.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ public interface ITokenCountProperty : IDocValuesProperty
2323
[DataMember(Name ="boost")]
2424
double? Boost { get; set; }
2525

26+
[DataMember(Name ="enable_position_increments")]
27+
bool? EnablePositionIncrements { get; set; }
28+
2629
[DataMember(Name ="index")]
2730
bool? Index { get; set; }
2831

@@ -35,13 +38,10 @@ public interface ITokenCountProperty : IDocValuesProperty
3538
public class TokenCountProperty : DocValuesPropertyBase, ITokenCountProperty
3639
{
3740
public TokenCountProperty() : base(FieldType.TokenCount) { }
38-
3941
public string Analyzer { get; set; }
40-
4142
public double? Boost { get; set; }
42-
43+
public bool? EnablePositionIncrements { get; set; }
4344
public bool? Index { get; set; }
44-
4545
public double? NullValue { get; set; }
4646
}
4747

@@ -55,6 +55,7 @@ public TokenCountPropertyDescriptor() : base(FieldType.TokenCount) { }
5555

5656
string ITokenCountProperty.Analyzer { get; set; }
5757
double? ITokenCountProperty.Boost { get; set; }
58+
bool? ITokenCountProperty.EnablePositionIncrements { get; set; }
5859
bool? ITokenCountProperty.Index { get; set; }
5960
double? ITokenCountProperty.NullValue { get; set; }
6061

@@ -63,8 +64,10 @@ public TokenCountPropertyDescriptor() : base(FieldType.TokenCount) { }
6364
[Obsolete("The server always treated this as a noop and has been removed in 7.10")]
6465
public TokenCountPropertyDescriptor<T> Boost(double? boost) => Assign(boost, (a, v) => a.Boost = v);
6566

66-
public TokenCountPropertyDescriptor<T> Index(bool? index = true) => Assign(index, (a, v) => a.Index = v);
67+
public TokenCountPropertyDescriptor<T> EnablePositionIncrements(bool? enablePositionIncrements = true) =>
68+
Assign(enablePositionIncrements, (a, v) => a.EnablePositionIncrements = v);
6769

70+
public TokenCountPropertyDescriptor<T> Index(bool? index = true) => Assign(index, (a, v) => a.Index = v);
6871
public TokenCountPropertyDescriptor<T> NullValue(double? nullValue) => Assign(nullValue, (a, v) => a.NullValue = v);
6972
}
7073
}

tests/Tests/Mapping/Types/Specialized/TokenCount/TokenCountAttributeTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public class TokenCountTest
1212
Index = false,
1313
Analyzer = "standard",
1414
Boost = 1.2,
15+
EnablePositionIncrements = false,
1516
NullValue = 0)]
1617
public int Full { get; set; }
1718

@@ -29,6 +30,7 @@ public class TokenCountAttributeTests : AttributeTestsBase<TokenCountTest>
2930
{
3031
type = "token_count",
3132
analyzer = "standard",
33+
enable_position_increments = false,
3234
index = false,
3335
boost = 1.2,
3436
null_value = 0.0,

tests/Tests/Mapping/Types/Specialized/TokenCount/TokenCountPropertyTests.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public TokenCountPropertyTests(WritableCluster cluster, EndpointUsage usage) : b
2222
{
2323
type = "token_count",
2424
analyzer = "standard",
25+
enable_position_increments = false,
2526
index = false,
2627
null_value = 0.0
2728
}
@@ -32,6 +33,7 @@ public TokenCountPropertyTests(WritableCluster cluster, EndpointUsage usage) : b
3233
.TokenCount(s => s
3334
.Name(p => p.Name)
3435
.Analyzer("standard")
36+
.EnablePositionIncrements(false)
3537
.Index(false)
3638
.NullValue(0.0)
3739
);
@@ -44,6 +46,7 @@ public TokenCountPropertyTests(WritableCluster cluster, EndpointUsage usage) : b
4446
{
4547
Index = false,
4648
Analyzer = "standard",
49+
EnablePositionIncrements = false,
4750
NullValue = 0.0
4851
}
4952
}

0 commit comments

Comments
 (0)