Skip to content

Commit

Permalink
Add support for search ext parameter
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Farr <[email protected]>
  • Loading branch information
Xtansia committed Aug 2, 2024
1 parent f3bae74 commit 700d05b
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- 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))
- Added support for serializing the `DateOnly` and `TimeOnly` types ([#734](https://github.com/opensearch-project/opensearch-net/pull/734))
- Added support for the `Ext` parameter on `SearchRequest` ([#]())

### Removed
- Removed support for the `net461` target ([#256](https://github.com/opensearch-project/opensearch-net/pull/256))
Expand Down
15 changes: 15 additions & 0 deletions src/OpenSearch.Client/Search/Search/SearchRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@ public partial interface ISearchRequest : ITypedSearchRequest
/// </summary>
[DataMember(Name = "runtime_mappings")]
IRuntimeFields RuntimeFields { get; set; }

[DataMember(Name = "ext")]
[JsonFormatter(typeof(VerbatimDictionaryInterfaceKeysFormatter<string, object>))]
IDictionary<string, object> Ext { get; set; }
}

[ReadAs(typeof(SearchRequest<>))]
Expand Down Expand Up @@ -288,6 +292,8 @@ public partial class SearchRequest
public bool? Version { get; set; }
/// <inheritdoc />
public IRuntimeFields RuntimeFields { get; set; }
/// <inheritdoc />
public IDictionary<string, object> Ext { get; set; }

protected override HttpMethod HttpMethod =>
RequestState.RequestParameters?.ContainsQueryString("source") == true
Expand Down Expand Up @@ -347,6 +353,7 @@ public partial class SearchDescriptor<TInferDocument> where TInferDocument : cla
TrackTotalHits ISearchRequest.TrackTotalHits { get; set; }
bool? ISearchRequest.Version { get; set; }
IRuntimeFields ISearchRequest.RuntimeFields { get; set; }
IDictionary<string, object> ISearchRequest.Ext { get; set; }

protected sealed override void RequestDefaults(SearchRequestParameters parameters) => TypedKeys();

Expand Down Expand Up @@ -538,6 +545,14 @@ public SearchDescriptor<TInferDocument> PointInTime(Func<PointInTimeDescriptor,
if (a.PointInTime != null) a.RouteValues.Remove("index");
});

/// <inheritdoc cref="ISearchRequest.Ext"/>
public SearchDescriptor<TInferDocument> Ext(Func<FluentDictionary<string, object>, FluentDictionary<string, object>> selector) =>
Assign(selector(new FluentDictionary<string, object>()), (a, v) => a.Ext = v);

/// <inheritdoc cref="ISearchRequest.Ext"/>
public SearchDescriptor<TInferDocument> Ext(IDictionary<string, object> dictionary) =>
Assign(dictionary, (a, v) => a.Ext = v);

protected override string ResolveUrl(RouteValues routeValues, IConnectionSettingsValues settings) => base.ResolveUrl(routeValues, settings);
}
}
31 changes: 28 additions & 3 deletions tests/Tests/Search/Search/SearchApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,15 @@ public SearchApiTests(ReadOnlyCluster cluster, EndpointUsage usage) : base(clust
value = "Stable"
}
}
}
},
ext = new
{
personalize_request_parameters = new
{
user_id = "<USER_ID>",
context = new { DEVICE = "mobile phone"}
}
}
};

protected override int ExpectStatusCode => 200;
Expand All @@ -93,7 +101,13 @@ public SearchApiTests(ReadOnlyCluster cluster, EndpointUsage usage) : base(clust
)
.PostFilter(f => f
.Term(p => p.State, StateOfBeing.Stable)
);
)
.Ext(e => e
.Add("personalize_request_parameters", new Dictionary<string, object>
{
["user_id"] = "<USER_ID>",
["context"] = new Dictionary<string, string>{ ["DEVICE"] = "mobile phone" }
}));

protected override HttpMethod HttpMethod => HttpMethod.POST;

Expand All @@ -110,7 +124,18 @@ public SearchApiTests(ReadOnlyCluster cluster, EndpointUsage usage) : base(clust
{
Field = "state",
Value = "Stable"
})
}),
Ext = new Dictionary<string, object>
{
["personalize_request_parameters"] = new Dictionary<string, object>
{
["user_id"] = "<USER_ID>",
["context"] = new Dictionary<string, string>
{
["DEVICE"] = "mobile phone"
}
}
}
};

protected override string UrlPath => $"/project/_search";
Expand Down

0 comments on commit 700d05b

Please sign in to comment.