Skip to content

Commit

Permalink
Merge pull request #788 from watson-developer-cloud/discovery-aggrega…
Browse files Browse the repository at this point in the history
…tion-models

Discovery aggregation models
  • Loading branch information
glennrfisher authored Apr 9, 2018
2 parents 5d200ee + 76542a7 commit 2955ff5
Show file tree
Hide file tree
Showing 12 changed files with 278 additions and 61 deletions.
14 changes: 5 additions & 9 deletions Source/DiscoveryV1/Models/Calculation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,27 @@ public struct Calculation: Decodable {
/// The type of aggregation command used. For example: term, filter, max, min, etc.
public var type: String?

/// The field where the aggregation is located in the document.
public var field: String?

public var results: [AggregationResult]?

/// The match the aggregated results queried for.
public var match: String?

/// Number of matching results.
public var matchingResults: Int?

/// Aggregations returned by the Discovery service.
public var aggregations: [QueryAggregation]?

/// Value of the aggregation. (For 'max' and 'min' type).
/// The field where the aggregation is located in the document.
public var field: String?

/// Value of the aggregation.
public var value: Double?

// Map each property name to the key that shall be used for encoding/decoding.
private enum CodingKeys: String, CodingKey {
case type = "type"
case field = "field"
case results = "results"
case match = "match"
case matchingResults = "matching_results"
case aggregations = "aggregations"
case field = "field"
case value = "value"
}

Expand Down
45 changes: 45 additions & 0 deletions Source/DiscoveryV1/Models/Filter.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* Copyright IBM Corporation 2018
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/

import Foundation

/** Filter. */
public struct Filter: Decodable {

/// The type of aggregation command used. For example: term, filter, max, min, etc.
public var type: String?

public var results: [AggregationResult]?

/// Number of matching results.
public var matchingResults: Int?

/// Aggregations returned by the Discovery service.
public var aggregations: [QueryAggregation]?

/// The match the aggregated results queried for.
public var match: String?

// Map each property name to the key that shall be used for encoding/decoding.
private enum CodingKeys: String, CodingKey {
case type = "type"
case results = "results"
case matchingResults = "matching_results"
case aggregations = "aggregations"
case match = "match"
}

}
8 changes: 0 additions & 8 deletions Source/DiscoveryV1/Models/GenericQueryAggregation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,8 @@ public struct GenericQueryAggregation: Decodable {
/// The type of aggregation command used. For example: term, filter, max, min, etc.
public var type: String?

/// The field where the aggregation is located in the document.
public var field: String?

public var results: [AggregationResult]?

/// The match the aggregated results queried for.
public var match: String?

/// Number of matching results.
public var matchingResults: Int?

Expand All @@ -39,9 +33,7 @@ public struct GenericQueryAggregation: Decodable {
// Map each property name to the key that shall be used for encoding/decoding.
private enum CodingKeys: String, CodingKey {
case type = "type"
case field = "field"
case results = "results"
case match = "match"
case matchingResults = "matching_results"
case aggregations = "aggregations"
}
Expand Down
12 changes: 4 additions & 8 deletions Source/DiscoveryV1/Models/Histogram.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,27 @@ public struct Histogram: Decodable {
/// The type of aggregation command used. For example: term, filter, max, min, etc.
public var type: String?

/// The field where the aggregation is located in the document.
public var field: String?

public var results: [AggregationResult]?

/// The match the aggregated results queried for.
public var match: String?

/// Number of matching results.
public var matchingResults: Int?

/// Aggregations returned by the Discovery service.
public var aggregations: [QueryAggregation]?

/// The field where the aggregation is located in the document.
public var field: String?

/// Interval of the aggregation. (For 'histogram' type).
public var interval: Int?

// Map each property name to the key that shall be used for encoding/decoding.
private enum CodingKeys: String, CodingKey {
case type = "type"
case field = "field"
case results = "results"
case match = "match"
case matchingResults = "matching_results"
case aggregations = "aggregations"
case field = "field"
case interval = "interval"
}

Expand Down
45 changes: 45 additions & 0 deletions Source/DiscoveryV1/Models/Nested.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* Copyright IBM Corporation 2018
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/

import Foundation

/** Nested. */
public struct Nested: Decodable {

/// The type of aggregation command used. For example: term, filter, max, min, etc.
public var type: String?

public var results: [AggregationResult]?

/// Number of matching results.
public var matchingResults: Int?

/// Aggregations returned by the Discovery service.
public var aggregations: [QueryAggregation]?

/// The area of the results the aggregation was restricted to.
public var path: String?

// Map each property name to the key that shall be used for encoding/decoding.
private enum CodingKeys: String, CodingKey {
case type = "type"
case results = "results"
case matchingResults = "matching_results"
case aggregations = "aggregations"
case path = "path"
}

}
20 changes: 10 additions & 10 deletions Source/DiscoveryV1/Models/QueryAggregation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ public enum QueryAggregation: Decodable {
// reference: https://console.bluemix.net/docs/services/discovery/query-reference.html#aggregations

case term(Term)
case filter(GenericQueryAggregation)
case nested(GenericQueryAggregation)
case filter(Filter)
case nested(Nested)
case histogram(Histogram)
case timeslice(GenericQueryAggregation)
case topHits(GenericQueryAggregation)
case uniqueCount(GenericQueryAggregation)
case timeslice(Timeslice)
case topHits(TopHits)
case uniqueCount(Calculation)
case max(Calculation)
case min(Calculation)
case average(Calculation)
Expand All @@ -49,12 +49,12 @@ public enum QueryAggregation: Decodable {
}
switch type {
case "term": self = .term(try Term(from: decoder))
case "filter": self = .filter(try GenericQueryAggregation(from: decoder))
case "nested": self = .nested(try GenericQueryAggregation(from: decoder))
case "filter": self = .filter(try Filter(from: decoder))
case "nested": self = .nested(try Nested(from: decoder))
case "histogram": self = .histogram(try Histogram(from: decoder))
case "timeslice": self = .timeslice(try GenericQueryAggregation(from: decoder))
case "top_hits": self = .topHits(try GenericQueryAggregation(from: decoder))
case "unique_count": self = .uniqueCount(try GenericQueryAggregation(from: decoder))
case "timeslice": self = .timeslice(try Timeslice(from: decoder))
case "top_hits": self = .topHits(try TopHits(from: decoder))
case "unique_count": self = .uniqueCount(try Calculation(from: decoder))
case "max": self = .max(try Calculation(from: decoder))
case "min": self = .min(try Calculation(from: decoder))
case "average": self = .average(try Calculation(from: decoder))
Expand Down
12 changes: 4 additions & 8 deletions Source/DiscoveryV1/Models/Term.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,26 @@ public struct Term: Decodable {
/// The type of aggregation command used. For example: term, filter, max, min, etc.
public var type: String?

/// The field where the aggregation is located in the document.
public var field: String?

public var results: [AggregationResult]?

/// The match the aggregated results queried for.
public var match: String?

/// Number of matching results.
public var matchingResults: Int?

/// Aggregations returned by the Discovery service.
public var aggregations: [QueryAggregation]?

/// The field where the aggregation is located in the document.
public var field: String?

public var count: Int?

// Map each property name to the key that shall be used for encoding/decoding.
private enum CodingKeys: String, CodingKey {
case type = "type"
case field = "field"
case results = "results"
case match = "match"
case matchingResults = "matching_results"
case aggregations = "aggregations"
case field = "field"
case count = "count"
}

Expand Down
53 changes: 53 additions & 0 deletions Source/DiscoveryV1/Models/Timeslice.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* Copyright IBM Corporation 2018
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/

import Foundation

/** Timeslice. */
public struct Timeslice: Decodable {

/// The type of aggregation command used. For example: term, filter, max, min, etc.
public var type: String?

public var results: [AggregationResult]?

/// Number of matching results.
public var matchingResults: Int?

/// Aggregations returned by the Discovery service.
public var aggregations: [QueryAggregation]?

/// The field where the aggregation is located in the document.
public var field: String?

/// Interval of the aggregation. Valid date interval values are second/seconds minute/minutes, hour/hours, day/days, week/weeks, month/months, and year/years.
public var interval: String?

/// Used to inducate that anomaly detection should be performed. Anomaly detection is used to locate unusual datapoints within a time series.
public var anomaly: Bool?

// Map each property name to the key that shall be used for encoding/decoding.
private enum CodingKeys: String, CodingKey {
case type = "type"
case results = "results"
case matchingResults = "matching_results"
case aggregations = "aggregations"
case field = "field"
case interval = "interval"
case anomaly = "anomaly"
}

}
48 changes: 48 additions & 0 deletions Source/DiscoveryV1/Models/TopHits.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* Copyright IBM Corporation 2018
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/

import Foundation

/** TopHits. */
public struct TopHits: Decodable {

/// The type of aggregation command used. For example: term, filter, max, min, etc.
public var type: String?

public var results: [AggregationResult]?

/// Number of matching results.
public var matchingResults: Int?

/// Aggregations returned by the Discovery service.
public var aggregations: [QueryAggregation]?

/// Number of top hits returned by the aggregation.
public var size: Int?

public var hits: TopHitsResults?

// Map each property name to the key that shall be used for encoding/decoding.
private enum CodingKeys: String, CodingKey {
case type = "type"
case results = "results"
case matchingResults = "matching_results"
case aggregations = "aggregations"
case size = "size"
case hits = "hits"
}

}
34 changes: 34 additions & 0 deletions Source/DiscoveryV1/Models/TopHitsResults.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* Copyright IBM Corporation 2018
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/

import Foundation

/** TopHitsResults. */
public struct TopHitsResults: Decodable {

/// Number of matching results.
public var matchingResults: Int?

/// Top results returned by the aggregation.
public var hits: [QueryResult]?

// Map each property name to the key that shall be used for encoding/decoding.
private enum CodingKeys: String, CodingKey {
case matchingResults = "matching_results"
case hits = "hits"
}

}
Loading

0 comments on commit 2955ff5

Please sign in to comment.