Skip to content

Commit

Permalink
Add support for enable_position_increments property on ITokenCountPro…
Browse files Browse the repository at this point in the history
…perty (#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 <russ.cam@forloop.co.uk>
(cherry picked from commit 70f9b5d)

Co-authored-by: Reji Dasan <rdasan@users.noreply.github.com>
  • Loading branch information
stevejgordon and rdasan authored Dec 22, 2020
1 parent 306c4be commit f78d25d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ public double Boost
#pragma warning restore 618
}

public bool EnablePositionIncrements
{
get => Self.EnablePositionIncrements.GetValueOrDefault(true);
set => Self.EnablePositionIncrements = value;
}

public bool Index
{
get => Self.Index.GetValueOrDefault();
Expand All @@ -36,6 +42,7 @@ public double NullValue

string ITokenCountProperty.Analyzer { get; set; }
double? ITokenCountProperty.Boost { get; set; }
bool? ITokenCountProperty.EnablePositionIncrements { get; set; }
bool? ITokenCountProperty.Index { get; set; }
double? ITokenCountProperty.NullValue { get; set; }
private ITokenCountProperty Self => this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public interface ITokenCountProperty : IDocValuesProperty
[DataMember(Name ="boost")]
double? Boost { get; set; }

[DataMember(Name ="enable_position_increments")]
bool? EnablePositionIncrements { get; set; }

[DataMember(Name ="index")]
bool? Index { get; set; }

Expand All @@ -35,13 +38,10 @@ public interface ITokenCountProperty : IDocValuesProperty
public class TokenCountProperty : DocValuesPropertyBase, ITokenCountProperty
{
public TokenCountProperty() : base(FieldType.TokenCount) { }

public string Analyzer { get; set; }

public double? Boost { get; set; }

public bool? EnablePositionIncrements { get; set; }
public bool? Index { get; set; }

public double? NullValue { get; set; }
}

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

string ITokenCountProperty.Analyzer { get; set; }
double? ITokenCountProperty.Boost { get; set; }
bool? ITokenCountProperty.EnablePositionIncrements { get; set; }
bool? ITokenCountProperty.Index { get; set; }
double? ITokenCountProperty.NullValue { get; set; }

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

public TokenCountPropertyDescriptor<T> Index(bool? index = true) => Assign(index, (a, v) => a.Index = v);
public TokenCountPropertyDescriptor<T> EnablePositionIncrements(bool? enablePositionIncrements = true) =>
Assign(enablePositionIncrements, (a, v) => a.EnablePositionIncrements = v);

public TokenCountPropertyDescriptor<T> Index(bool? index = true) => Assign(index, (a, v) => a.Index = v);
public TokenCountPropertyDescriptor<T> NullValue(double? nullValue) => Assign(nullValue, (a, v) => a.NullValue = v);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class TokenCountTest
Index = false,
Analyzer = "standard",
Boost = 1.2,
EnablePositionIncrements = false,
NullValue = 0)]
public int Full { get; set; }

Expand All @@ -29,6 +30,7 @@ public class TokenCountAttributeTests : AttributeTestsBase<TokenCountTest>
{
type = "token_count",
analyzer = "standard",
enable_position_increments = false,
index = false,
boost = 1.2,
null_value = 0.0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public TokenCountPropertyTests(WritableCluster cluster, EndpointUsage usage) : b
{
type = "token_count",
analyzer = "standard",
enable_position_increments = false,
index = false,
null_value = 0.0
}
Expand All @@ -32,6 +33,7 @@ public TokenCountPropertyTests(WritableCluster cluster, EndpointUsage usage) : b
.TokenCount(s => s
.Name(p => p.Name)
.Analyzer("standard")
.EnablePositionIncrements(false)
.Index(false)
.NullValue(0.0)
);
Expand All @@ -44,6 +46,7 @@ public TokenCountPropertyTests(WritableCluster cluster, EndpointUsage usage) : b
{
Index = false,
Analyzer = "standard",
EnablePositionIncrements = false,
NullValue = 0.0
}
}
Expand Down

0 comments on commit f78d25d

Please sign in to comment.