Skip to content

Commit 488e6e9

Browse files
committed
fix #1359 randomscore now accepts strings
1 parent 164392c commit 488e6e9

File tree

5 files changed

+13
-6
lines changed

5 files changed

+13
-6
lines changed

src/Nest/CommonAbstractions/Infer/ExpressionVisitor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace Nest
99
/// This comes from Matt Warren's sample:
1010
/// http://blogs.msdn.com/mattwar/archive/2007/07/31/linq-building-an-iqueryable-provider-part-ii.aspx
1111
/// </summary>
12-
public abstract class ExpressionVisitor
12+
public abstract class ExpressionVisitor
1313
{
1414
public virtual Expression Visit(Expression exp, Stack<string> stack, Stack<ElasticsearchPropertyAttribute> properties)
1515
{

src/Nest/QueryDsl/Compound/FunctionScore/Functions/Random/RandomScoreFunction.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,21 @@ namespace Nest
77
public interface IRandomScoreFunction : IScoreFunction
88
{
99
[JsonProperty(PropertyName = "seed")]
10-
int? Seed { get; set; }
10+
Union<long, string> Seed { get; set; }
1111
}
1212

1313
public class RandomScoreFunction: FunctionScoreFunctionBase, IRandomScoreFunction
1414
{
15-
public int? Seed { get; set; }
15+
public Union<long, string> Seed { get; set; }
1616
}
1717

1818
public class RandomScoreFunctionDescriptor<T> : FunctionScoreFunctionBaseDescriptor<RandomScoreFunctionDescriptor<T>, IRandomScoreFunction,T>, IRandomScoreFunction
1919
where T : class
2020
{
21-
int? IRandomScoreFunction.Seed { get; set; }
21+
Union<long, string> IRandomScoreFunction.Seed { get; set; }
2222

23-
public RandomScoreFunctionDescriptor<T> Seed(int? seed) => Assign(a => a.Seed = seed);
23+
public RandomScoreFunctionDescriptor<T> Seed(long? seed) => Assign(a => a.Seed = seed);
24+
public RandomScoreFunctionDescriptor<T> Seed(string seed) => Assign(a => a.Seed = seed);
2425

2526
}
2627
}

src/Nest/QueryDsl/Compound/FunctionScore/Functions/ScoreFunctions.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ public ScoreFunctionsDescriptor<T> FieldValueFactor(Func<FieldValueFactorFunctio
4444
public ScoreFunctionsDescriptor<T> RandomScore(Func<RandomScoreFunctionDescriptor<T>, IRandomScoreFunction> selector) =>
4545
Assign(a => a.AddIfNotNull(selector?.Invoke(new RandomScoreFunctionDescriptor<T>())));
4646

47-
public ScoreFunctionsDescriptor<T> RandomScore(int? seed) => Assign(a => a.AddIfNotNull(new RandomScoreFunction { Seed = seed }));
47+
public ScoreFunctionsDescriptor<T> RandomScore(long? seed) => Assign(a => a.AddIfNotNull(new RandomScoreFunction { Seed = seed }));
48+
49+
public ScoreFunctionsDescriptor<T> RandomScore(string seed) => Assign(a => a.AddIfNotNull(new RandomScoreFunction { Seed = seed }));
4850

4951
public ScoreFunctionsDescriptor<T> Weight(Func<WeightFunctionDescriptor<T>, IWeightFunction> selector) =>
5052
Assign(a => a.AddIfNotNull(selector?.Invoke(new WeightFunctionDescriptor<T>())));

src/Nest/Search/Search/SearchRequest.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ public partial interface ISearchRequest : ICovariantSearchRequest
8484

8585
bool? IgnoreUnavalable { get; }
8686
}
87+
8788
public partial interface ISearchRequest<T> : ISearchRequest { }
8889

8990
public partial class SearchRequest

src/Tests/QueryDsl/Compound/FunctionScore/FunctionScoreQueryUsageTests.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public FunctionScoreQueryUsageTests(ReadOnlyCluster i, EndpointUsage usage) : ba
6060
}
6161
},
6262
new { random_score = new { seed = 1337 } },
63+
new { random_score = new { seed = "randomstring" } },
6364
new { weight = 1.0 },
6465
new {
6566
script_score = new {
@@ -98,6 +99,7 @@ public FunctionScoreQueryUsageTests(ReadOnlyCluster i, EndpointUsage usage) : ba
9899
Field = "x", Factor = 1.1, Missing = 0.1, Modifier = FieldValueFactorModifier.Ln
99100
},
100101
new RandomScoreFunction { Seed = 1337 },
102+
new RandomScoreFunction { Seed = "randomstring" },
101103
new WeightFunction { Weight = 1.0},
102104
new ScriptScoreFunction { Script = new ScriptQuery { File = "x" } }
103105
}
@@ -118,6 +120,7 @@ protected override QueryContainer QueryFluent(QueryContainerDescriptor<Project>
118120
.LinearGeoLocation(b => b.Field(p => p.Location).Origin(new GeoLocation(70, -70)).Scale(Distance.Miles(1)).MultiValueMode(MultiValueMode.Average))
119121
.FieldValueFactor(b => b.Field("x").Factor(1.1).Missing(0.1).Modifier(FieldValueFactorModifier.Ln))
120122
.RandomScore(1337)
123+
.RandomScore("randomstring")
121124
.Weight(1.0)
122125
.ScriptScore(ss => ss.Script(s => s.File("x")))
123126
)

0 commit comments

Comments
 (0)