From 079b80ff82da3382441b8244b0b87ae52571271a Mon Sep 17 00:00:00 2001 From: Samuel Date: Tue, 30 Apr 2024 23:03:16 +0100 Subject: [PATCH] feat: add support for min_score on ScriptScoreQuery (#624) * feat: add support for min_score on ScriptScoreQuery Signed-off-by: Samuel Cox Signed-off-by: Samuel * style: remove empty line Signed-off-by: Samuel Signed-off-by: Samuel --------- Signed-off-by: Samuel Cox Signed-off-by: Samuel (cherry picked from commit 8d8951957e613612b30cc2949e822b4b63cc7c5a) --- CHANGELOG.md | 5 ++++- .../Specialized/ScriptScore/ScriptScoreQuery.cs | 17 ++++++++++++++++- .../ScriptScore/ScriptScoreQueryUsageTests.cs | 3 +++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 99218ca387..ffca71c8c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ## [Unreleased] +### Added +- Added support for `MinScore` on `ScriptScoreQuery` ([#624](https://github.com/opensearch-project/opensearch-net/pull/624)) + ### Dependencies - Bumps `AWSSDK.Core` from 3.7.204.12 to 3.7.303.18 - Bumps `Bogus` from 35.3.0 to 35.5.1 @@ -164,4 +167,4 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) [1.6.0]: https://github.com/opensearch-project/opensearch-net/compare/v1.5.0...v1.6.0 [1.5.0]: https://github.com/opensearch-project/opensearch-net/compare/v1.4.0...v1.5.0 [1.4.0]: https://github.com/opensearch-project/opensearch-net/compare/v1.3.0...v1.4.0 -[1.3.0]: https://github.com/opensearch-project/opensearch-net/compare/v1.2.0...v1.3.0 \ No newline at end of file +[1.3.0]: https://github.com/opensearch-project/opensearch-net/compare/v1.2.0...v1.3.0 diff --git a/src/OpenSearch.Client/QueryDsl/Specialized/ScriptScore/ScriptScoreQuery.cs b/src/OpenSearch.Client/QueryDsl/Specialized/ScriptScore/ScriptScoreQuery.cs index b3a852de42..a5e1851988 100644 --- a/src/OpenSearch.Client/QueryDsl/Specialized/ScriptScore/ScriptScoreQuery.cs +++ b/src/OpenSearch.Client/QueryDsl/Specialized/ScriptScore/ScriptScoreQuery.cs @@ -52,6 +52,12 @@ public interface IScriptScoreQuery : IQuery /// [DataMember(Name = "script")] IScript Script { get; set; } + + /// + /// The score above which documents will be returned + /// + [DataMember(Name = "min_score")] + double? MinScore { get; set; } } /// @@ -63,6 +69,9 @@ public class ScriptScoreQuery : QueryBase, IScriptScoreQuery /// public IScript Script { get; set; } + /// + public double? MinScore { get; set; } + protected override bool Conditionless => IsConditionless(this); internal override void InternalWrapInContainer(IQueryContainer c) => c.ScriptScore = this; @@ -94,6 +103,8 @@ public class ScriptScoreQueryDescriptor IScript IScriptScoreQuery.Script { get; set; } + double? IScriptScoreQuery.MinScore { get; set; } + /// public ScriptScoreQueryDescriptor Query(Func, QueryContainer> selector) => Assign(selector, (a, v) => a.Query = v?.Invoke(new QueryContainerDescriptor())); @@ -101,5 +112,9 @@ public ScriptScoreQueryDescriptor Query(Func, Que /// public ScriptScoreQueryDescriptor Script(Func selector) => Assign(selector, (a, v) => a.Script = v?.Invoke(new ScriptDescriptor())); - } + + /// + public ScriptScoreQueryDescriptor MinScore(double? minScore) => Assign(minScore, (a, v) => a.MinScore = v); + + } } diff --git a/tests/Tests/QueryDsl/Specialized/ScriptScore/ScriptScoreQueryUsageTests.cs b/tests/Tests/QueryDsl/Specialized/ScriptScore/ScriptScoreQueryUsageTests.cs index ff4ec9a21b..d7ed178cab 100644 --- a/tests/Tests/QueryDsl/Specialized/ScriptScore/ScriptScoreQueryUsageTests.cs +++ b/tests/Tests/QueryDsl/Specialized/ScriptScore/ScriptScoreQueryUsageTests.cs @@ -79,6 +79,7 @@ public ScriptScoreQueryUsageTests(ReadOnlyCluster i, EndpointUsage usage) : base { Name = "named_query", Boost = 1.1, + MinScore = 1.2, Query = new NumericRangeQuery { Field = Infer.Field(f => f.NumberOfCommits), @@ -102,6 +103,7 @@ public ScriptScoreQueryUsageTests(ReadOnlyCluster i, EndpointUsage usage) : base { _name = "named_query", boost = 1.1, + min_score = 1.2, query = new { range = new @@ -130,6 +132,7 @@ protected override QueryContainer QueryFluent(QueryContainerDescriptor .ScriptScore(sn => sn .Name("named_query") .Boost(1.1) + .MinScore(1.2) .Query(qq => qq .Range(r => r .Field(f => f.NumberOfCommits)