Skip to content

Commit 31b41e5

Browse files
committed
feat(Discovery v2): Discriminator for QueryAggregation
1 parent dd895de commit 31b41e5

9 files changed

+21
-7
lines changed

src/IBM.Watson.Discovery.v2/IBM.Watson.Discovery.v2.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
<ItemGroup>
2828
<PackageReference Include="IBM.Cloud.SDK.Core" Version="1.1.0-rc01" />
2929
<PackageReference Include="IBM.Watson.Common" Version="4.0.0" />
30+
<PackageReference Include="JsonSubTypes" Version="1.6.0" />
3031
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
3132
</ItemGroup>
3233

src/IBM.Watson.Discovery.v2/Model/QueryAggregation.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,26 @@
1515
*
1616
*/
1717

18+
using JsonSubTypes;
1819
using Newtonsoft.Json;
1920

2021
namespace IBM.Watson.Discovery.v2.Model
2122
{
2223
/// <summary>
2324
/// An abstract aggregation type produced by Discovery to analyze the input provided.
2425
/// </summary>
26+
[JsonConverter(typeof(JsonSubtypes), "Type")]
27+
[JsonSubtypes.KnownSubType(typeof(QueryHistogramAggregation), "histogram")]
28+
[JsonSubtypes.KnownSubType(typeof(QueryCalculationAggregation), "max")]
29+
[JsonSubtypes.KnownSubType(typeof(QueryCalculationAggregation), "min")]
30+
[JsonSubtypes.KnownSubType(typeof(QueryCalculationAggregation), "average")]
31+
[JsonSubtypes.KnownSubType(typeof(QueryCalculationAggregation), "sum")]
32+
[JsonSubtypes.KnownSubType(typeof(QueryCalculationAggregation), "unique_count")]
33+
[JsonSubtypes.KnownSubType(typeof(QueryTermAggregation), "term")]
34+
[JsonSubtypes.KnownSubType(typeof(QueryFilterAggregation), "filter")]
35+
[JsonSubtypes.KnownSubType(typeof(QueryNestedAggregation), "nested")]
36+
[JsonSubtypes.KnownSubType(typeof(QueryTimesliceAggregation), "timeslice")]
37+
[JsonSubtypes.KnownSubType(typeof(QueryTopHitsAggregation), "top_hits")]
2538
public class QueryAggregation
2639
{
2740
/// <summary>

src/IBM.Watson.Discovery.v2/Model/QueryCalculationAggregation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace IBM.Watson.Discovery.v2.Model
2323
/// Returns a scalar calculation across all documents for the field specified. Possible calculations include min,
2424
/// max, sum, average, and unique_count.
2525
/// </summary>
26-
public class QueryCalculationAggregation
26+
public class QueryCalculationAggregation : QueryAggregation
2727
{
2828
/// <summary>
2929
/// The field to perform the calculation on.

src/IBM.Watson.Discovery.v2/Model/QueryFilterAggregation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace IBM.Watson.Discovery.v2.Model
2323
/// <summary>
2424
/// A modifier that will narrow down the document set of the sub aggregations it precedes.
2525
/// </summary>
26-
public class QueryFilterAggregation
26+
public class QueryFilterAggregation : QueryAggregation
2727
{
2828
/// <summary>
2929
/// The filter written in Discovery Query Language syntax applied to the documents before sub aggregations are

src/IBM.Watson.Discovery.v2/Model/QueryHistogramAggregation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace IBM.Watson.Discovery.v2.Model
2424
/// Numeric interval segments to categorize documents by using field values from a single numeric field to describe
2525
/// the category.
2626
/// </summary>
27-
public class QueryHistogramAggregation
27+
public class QueryHistogramAggregation : QueryAggregation
2828
{
2929
/// <summary>
3030
/// The numeric field name used to create the histogram.

src/IBM.Watson.Discovery.v2/Model/QueryNestedAggregation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace IBM.Watson.Discovery.v2.Model
2424
/// A restriction that alter the document set used for sub aggregations it precedes to nested documents found in the
2525
/// field specified.
2626
/// </summary>
27-
public class QueryNestedAggregation
27+
public class QueryNestedAggregation : QueryAggregation
2828
{
2929
/// <summary>
3030
/// The path to the document field to scope sub aggregations to.

src/IBM.Watson.Discovery.v2/Model/QueryTermAggregation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace IBM.Watson.Discovery.v2.Model
2323
/// <summary>
2424
/// Returns the top values for the field specified.
2525
/// </summary>
26-
public class QueryTermAggregation
26+
public class QueryTermAggregation : QueryAggregation
2727
{
2828
/// <summary>
2929
/// The field in the document used to generate top values from.

src/IBM.Watson.Discovery.v2/Model/QueryTimesliceAggregation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace IBM.Watson.Discovery.v2.Model
2323
/// <summary>
2424
/// A specialized histogram aggregation that uses dates to create interval segments.
2525
/// </summary>
26-
public class QueryTimesliceAggregation
26+
public class QueryTimesliceAggregation : QueryAggregation
2727
{
2828
/// <summary>
2929
/// The date field name used to create the timeslice.

src/IBM.Watson.Discovery.v2/Model/QueryTopHitsAggregation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace IBM.Watson.Discovery.v2.Model
2222
/// <summary>
2323
/// Returns the top documents ranked by the score of the query.
2424
/// </summary>
25-
public class QueryTopHitsAggregation
25+
public class QueryTopHitsAggregation : QueryAggregation
2626
{
2727
/// <summary>
2828
/// The number of documents to return.

0 commit comments

Comments
 (0)