Skip to content

Commit ba6b1a3

Browse files
committed
Merge pull request #541 from azubanov/NEST_patch_FunctionScoreQueryDescriptor
FunctionScoreQueryDescriptor boost_mode support
2 parents 91a16f7 + f6f8752 commit ba6b1a3

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/Nest/DSL/Query/FunctionScoreQueryDescriptor.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ public class FunctionScoreQueryDescriptor<T> : IQuery where T : class
2525
[JsonConverter(typeof(StringEnumConverter))]
2626
FunctionScoreMode? _ScoreMode { get; set; }
2727

28+
[JsonProperty(PropertyName = "boost_mode")]
29+
[JsonConverter(typeof(StringEnumConverter))]
30+
FunctionBoostMode? _BoostMode { get; set; }
31+
2832
[JsonProperty(PropertyName = "random_score")]
2933
RandomScoreFunction _RandomScore { get; set; }
3034

@@ -69,6 +73,12 @@ public FunctionScoreQueryDescriptor<T> ScoreMode(FunctionScoreMode mode)
6973
return this;
7074
}
7175

76+
public FunctionScoreQueryDescriptor<T> BoostMode(FunctionBoostMode mode)
77+
{
78+
this._BoostMode = mode;
79+
return this;
80+
}
81+
7282
public FunctionScoreQueryDescriptor<T> RandomScore(int? seed=null)
7383
{
7484
this._RandomScore = new RandomScoreFunction();
@@ -101,6 +111,16 @@ public enum FunctionScoreMode
101111
min
102112
}
103113

114+
public enum FunctionBoostMode
115+
{
116+
multiply,
117+
replace,
118+
sum,
119+
avg,
120+
max,
121+
min
122+
}
123+
104124
public class FunctionScoreFunctionsDescriptor<T> : IEnumerable<FunctionScoreFunction<T>> where T : class
105125
{
106126
internal List<FunctionScoreFunction<T>> _Functions { get; set; }

src/Tests/Nest.Tests.Unit/Search/Query/Singles/FunctionScoreQueryJson.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public void FunctionScoreQuery()
2121
f => f.BoostFactor(2)
2222
)
2323
.ScoreMode(FunctionScoreMode.sum)
24+
.BoostMode(FunctionBoostMode.replace)
2425
)
2526
).Fields(x => x.Content);
2627

@@ -36,7 +37,8 @@ public void FunctionScoreQuery()
3637
{boost_factor: 2.0 }
3738
],
3839
query : { match_all : {} },
39-
score_mode: 'sum'
40+
score_mode: 'sum',
41+
boost_mode: 'replace',
4042
}
4143
},
4244
fields: [""content""]

0 commit comments

Comments
 (0)