Skip to content

Commit

Permalink
Merge pull request #3 from msavoaia/feature/make-total-generic
Browse files Browse the repository at this point in the history
make total generic
  • Loading branch information
msavoaia authored Jan 19, 2023
2 parents c1984e2 + 602eb62 commit 236dbb0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions Sources/ElasticSwift/ElasticSwift.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public extension ElasticClient {
/// - serachRequest: the request
/// - options: the request options (e.g. headers), defaults to `RequestOptions.default` if nothing to be customized.
/// - completionHandler: callback to be invoked upon request completion.
func search<T: Codable>(_ serachRequest: SearchRequest, with options: RequestOptions = .default, completionHandler: @escaping (_ result: Result<SearchResponse<T>, Error>) -> Void) -> Void {
func search<T: Codable, Q: Codable>(_ serachRequest: SearchRequest, with options: RequestOptions = .default, completionHandler: @escaping (_ result: Result<SearchResponse<T, Q>, Error>) -> Void) -> Void {
return execute(request: serachRequest, options: options, completionHandler: completionHandler)
}

Expand All @@ -108,7 +108,7 @@ public extension ElasticClient {
/// - serachRequest: the request
/// - options: the request options (e.g. headers), defaults to `RequestOptions.default` if nothing to be customized.
/// - completionHandler: callback to be invoked upon request completion.
func scroll<T: Codable>(_ scrollRequest: SearchScrollRequest, with options: RequestOptions = .default, completionHandler: @escaping (_ result: Result<SearchResponse<T>, Error>) -> Void) -> Void {
func scroll<T: Codable, Q: Codable>(_ scrollRequest: SearchScrollRequest, with options: RequestOptions = .default, completionHandler: @escaping (_ result: Result<SearchResponse<T, Q>, Error>) -> Void) -> Void {
return execute(request: scrollRequest, options: options, completionHandler: completionHandler)
}

Expand Down Expand Up @@ -284,7 +284,7 @@ public extension ElasticClient {
/// - searchTemplateRequest: the request.
/// - options: the request options (e.g. headers), defaults to `RequestOptions.default` if nothing to be customized.
/// - completionHandler: callback to be invoked upon request completion.
func searchTemplate<T: Codable>(_ searchTemplateRequest: SearchTemplateRequest, with options: RequestOptions = .default, completionHandler: @escaping (_ result: Result<SearchResponse<T>, Error>) -> Void) {
func searchTemplate<T: Codable, Q: Codable>(_ searchTemplateRequest: SearchTemplateRequest, with options: RequestOptions = .default, completionHandler: @escaping (_ result: Result<SearchResponse<T, Q>, Error>) -> Void) {
return execute(request: searchTemplateRequest, options: options, completionHandler: completionHandler)
}
}
Expand Down
14 changes: 7 additions & 7 deletions Sources/ElasticSwift/Responses/Response.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ public struct IndexResponse: Codable, Equatable {

// MARK: - Search Response

public struct SearchResponse<T: Codable>: Codable, Equatable where T: Equatable {
public struct SearchResponse<T: Codable, Q: Codable>: Codable, Equatable where T: Equatable, Q: Equatable {
public let took: Int
public let timedOut: Bool
public let shards: Shards
public let hits: SearchHits<T>
public let hits: SearchHits<T, Q>
public let scrollId: String?
public let profile: SearchProfileShardResults?
public let suggest: [String: [SuggestEntry]]?
Expand Down Expand Up @@ -188,12 +188,12 @@ extension CollectorResult: Codable {

extension CollectorResult: Equatable {}

public struct SearchHits<T: Codable>: Codable, Equatable where T: Equatable {
public let total: Int
public struct SearchHits<T: Codable, Q: Codable>: Codable, Equatable where T: Equatable, Q: Equatable {
public let total: Q
public let maxScore: Decimal?
public let hits: [SearchHit<T>]

public init(total: Int, maxScore: Decimal?, hits: [SearchHit<T>] = []) {
public init(total: Q, maxScore: Decimal?, hits: [SearchHit<T>] = []) {
self.total = total
self.maxScore = maxScore
self.hits = hits
Expand All @@ -219,7 +219,7 @@ public struct SearchHit<T: Codable> where T: Equatable {
public let fields: [String: SearchHitField]?
public let explanation: Explanation?
public let matchedQueries: [String]?
public let innerHits: [String: SearchHits<CodableValue>]?
public let innerHits: [String: SearchHits<CodableValue, CodableValue>]?
public let node: String?
public let shard: String?
public let highlightFields: [String: HighlightField]?
Expand Down Expand Up @@ -323,7 +323,7 @@ extension SearchHit: Codable {
}

private struct InnerHitWrapper: Codable, Equatable {
public let hits: SearchHits<CodableValue>
public let hits: SearchHits<CodableValue, CodableValue>
}
}

Expand Down

0 comments on commit 236dbb0

Please sign in to comment.