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 <sam.r.c@hotmail.com>
Signed-off-by: Samuel <sam.r.c@hotmail.com>

* style: remove empty line Signed-off-by: Samuel <sam.r.c@hotmail.com>

Signed-off-by: Samuel <sam.r.c@hotmail.com>

---------

Signed-off-by: Samuel Cox <sam.r.c@hotmail.com>
Signed-off-by: Samuel <sam.r.c@hotmail.com>
  • Loading branch information
SamuelCox committed Apr 30, 2024
1 parent 6110c87 commit 8d89519
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- As part of [efforts to re-generate the client](https://github.com/opensearch-project/opensearch-net/pulls?q=is%3Apr+label%3Acode-gen+is%3Aclosed) from our [OpenAPI specification](https://github.com/opensearch-project/opensearch-api-specification) there have been numerous corrections and changes that resulted in breaking changes. Please refer to [UPGRADING.md](UPGRADING.md) for a complete list of these breakages and any relevant guidance for upgrading to this version of the client.

### Added
- Added support for `MinScore` on `ScriptScoreQuery` ([#624](https://github.com/opensearch-project/opensearch-net/pull/624))
- Added support for the `Cat.PitSegments` and `Cat.SegmentReplication` APIs ([#527](https://github.com/opensearch-project/opensearch-net/pull/527))

### Removed
Expand Down
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 8d89519

Please sign in to comment.