Skip to content

Commit

Permalink
feat: add support for min_score on ScriptScoreQuery (#624)
Browse files Browse the repository at this point in the history
* feat: add support for min_score on ScriptScoreQuery

Signed-off-by: Samuel Cox <[email protected]>
Signed-off-by: Samuel <[email protected]>

* style: remove empty line Signed-off-by: Samuel <[email protected]>

Signed-off-by: Samuel <[email protected]>

---------

Signed-off-by: Samuel Cox <[email protected]>
Signed-off-by: Samuel <[email protected]>
(cherry picked from commit 8d89519)
  • Loading branch information
SamuelCox authored and dblock committed May 1, 2024
1 parent 7be55e0 commit 079b80f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
[1.3.0]: https://github.com/opensearch-project/opensearch-net/compare/v1.2.0...v1.3.0
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ public interface IScriptScoreQuery : IQuery
/// </summary>
[DataMember(Name = "script")]
IScript Script { get; set; }

/// <summary>
/// The score above which documents will be returned
/// </summary>
[DataMember(Name = "min_score")]
double? MinScore { get; set; }
}

/// <inheritdoc cref="IScriptScoreQuery" />
Expand All @@ -63,6 +69,9 @@ public class ScriptScoreQuery : QueryBase, IScriptScoreQuery
/// <inheritdoc />
public IScript Script { get; set; }

/// <inheritdoc />
public double? MinScore { get; set; }

protected override bool Conditionless => IsConditionless(this);

internal override void InternalWrapInContainer(IQueryContainer c) => c.ScriptScore = this;
Expand Down Expand Up @@ -94,12 +103,18 @@ public class ScriptScoreQueryDescriptor<T>

IScript IScriptScoreQuery.Script { get; set; }

double? IScriptScoreQuery.MinScore { get; set; }

/// <inheritdoc cref="IScriptScoreQuery.Query" />
public ScriptScoreQueryDescriptor<T> Query(Func<QueryContainerDescriptor<T>, QueryContainer> selector) =>
Assign(selector, (a, v) => a.Query = v?.Invoke(new QueryContainerDescriptor<T>()));

/// <inheritdoc cref="IScriptScoreQuery.Script" />
public ScriptScoreQueryDescriptor<T> Script(Func<ScriptDescriptor, IScript> selector) =>
Assign(selector, (a, v) => a.Script = v?.Invoke(new ScriptDescriptor()));
}

/// <inheritdoc cref="IScriptScoreQuery.MinScore" />
public ScriptScoreQueryDescriptor<T> MinScore(double? minScore) => Assign(minScore, (a, v) => a.MinScore = v);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Project>(f => f.NumberOfCommits),
Expand All @@ -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
Expand Down Expand Up @@ -130,6 +132,7 @@ protected override QueryContainer QueryFluent(QueryContainerDescriptor<Project>
.ScriptScore(sn => sn
.Name("named_query")
.Boost(1.1)
.MinScore(1.2)
.Query(qq => qq
.Range(r => r
.Field(f => f.NumberOfCommits)
Expand Down

0 comments on commit 079b80f

Please sign in to comment.