Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for min_score on ScriptScoreQuery #624

Merged
merged 2 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading