Skip to content

Commit cdf6ff7

Browse files
committed
Add public constructor for SearchResponse & SearchResponses
1 parent 9d65a9d commit cdf6ff7

File tree

2 files changed

+39
-27
lines changed

2 files changed

+39
-27
lines changed

Sources/AlgoliaSearchClient/Models/Search/MultipleIndex/SearchesResponse.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ import Foundation
1010
public struct SearchesResponse: Codable {
1111

1212
/// List of result in the order they were submitted, one element for each IndexQuery.
13-
public let results: [SearchResponse]
13+
public var results: [SearchResponse]
14+
15+
public init(results: [SearchResponse]) {
16+
self.results = results
17+
}
1418

1519
}
20+
21+
extension SearchesResponse: Builder {}

Sources/AlgoliaSearchClient/Models/Search/Response/SearchResponse/SearchResponse.swift

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,59 +13,59 @@ public struct SearchResponse {
1313
The hits returned by the search. Hits are ordered according to the ranking or sorting of the index being queried.
1414
Hits are made of the schemaless JSON objects that you stored in the index.
1515
*/
16-
public let hits: [Hit<JSON>]
16+
public var hits: [Hit<JSON>]
1717

1818
/**
1919
The number of hits matched by the query.
2020
*/
21-
public let nbHits: Int?
21+
public var nbHits: Int?
2222

2323
/**
2424
Index of the current page (zero-based). See the Query.page search parameter.
2525
- Not returned if you use offset/length for pagination.
2626
*/
27-
public let page: Int?
27+
public var page: Int?
2828

2929
/**
3030
The maximum number of hits returned per page. See the Query.hitsPerPage search parameter.
3131
- Not returned if you use offset & length for pagination.
3232
*/
33-
public let hitsPerPage: Int?
33+
public var hitsPerPage: Int?
3434

3535
/**
3636
Alternative to page (zero-based). Is returned only when Query.offset Query.length is specified.
3737
*/
38-
public let offset: Int?
38+
public var offset: Int?
3939

4040
/**
4141
Alternative to hitsPerPageOrNull (zero-based). Is returned only when Query.offset Query.length is specified.
4242
*/
43-
public let length: Int?
43+
public var length: Int?
4444

4545
/**
4646
Array of userData object. Only returned if at least one query rule containing a custom userData
4747
consequence was applied.
4848
*/
49-
public let userData: [JSON]?
49+
public var userData: [JSON]?
5050

5151
/**
5252
The number of returned pages. Calculation is based on the total number of hits (nbHits) divided by the number of
5353
hits per page (hitsPerPage), rounded up to the nearest integer.
5454
- Not returned if you use offset & length for pagination.
5555
*/
56-
public let nbPages: Int?
56+
public var nbPages: Int?
5757

5858
/**
5959
Time the server took to process the request, in milliseconds. This does not include network time.
6060
*/
61-
public let processingTimeMS: TimeInterval?
61+
public var processingTimeMS: TimeInterval?
6262

6363
/**
6464
Whether the nbHits is exhaustive (true) or approximate (false). An approximation is done when the query takes
6565
more than 50ms to be processed (this can happen when using complex filters on millions on records).
6666
- See the related [discussion](https://www.algolia.com/doc/faq/index-configuration/my-facet-and-hit-counts-are-not-accurate/)
6767
*/
68-
public let exhaustiveNbHits: Bool?
68+
public var exhaustiveNbHits: Bool?
6969

7070
/**
7171
Whether the facet count is exhaustive (true) or approximate (false).
@@ -76,56 +76,56 @@ public struct SearchResponse {
7676
/**
7777
An echo of the query text. See the Query.query search parameter.
7878
*/
79-
public let query: String?
79+
public var query: String?
8080

8181
/**
8282
A markup text indicating which parts of the original query have been removed in order to retrieve a non-empty result set.
8383
- The removed parts are surrounded by <em> tags.
8484
- Only returned when Query.removeWordsIfNoResults or Settings.removeWordsIfNoResults is set to RemoveWordIfNoResults.LastWords or RemoveWordIfNoResults.FirstWords.
8585
*/
86-
public let queryAfterRemoval: String?
86+
public var queryAfterRemoval: String?
8787

8888
/**
8989
A url-encoded string of all Query parameters.
9090
*/
91-
public let params: String?
91+
public var params: String?
9292

9393
/**
9494
Used to return warnings about the query.
9595
*/
96-
public let message: String?
96+
public var message: String?
9797

9898
/**
9999
The computed geo location.
100100
- Only returned when Query.aroundLatLngViaIP or Query.aroundLatLng is set.
101101
*/
102-
public let aroundLatLng: Point?
102+
public var aroundLatLng: Point?
103103

104104
/**
105105
The automatically computed radius. For legacy reasons, this parameter is a string and not an integer.
106106
- Only returned for geo queries without an explicitly specified Query.aroundRadius.
107107
*/
108-
public let automaticRadius: Double?
108+
public var automaticRadius: Double?
109109

110110
/**
111111
Actual host name of the server that processed the request. Our DNS supports automatic failover and load
112112
balancing, so this may differ from the host name used in the request.
113113
- Returned only if Query.getRankingInfo is set to true.
114114
*/
115-
public let serverUsed: String?
115+
public var serverUsed: String?
116116

117117
/**
118118
Index name used for the query. In case of A/B test, the index targeted isn’t always the index used by the query.
119119
- Returned only if Query.getRankingInfo is set to true.
120120
*/
121-
public let indexUsed: IndexName?
121+
public var indexUsed: IndexName?
122122

123123
/**
124124
In case of A/B test, reports the variant ID used. The variant ID is the position in the array of variants
125125
(starting at 1).
126126
- Returned only if [Query.getRankingInfo] is set to true.
127127
*/
128-
public let abTestVariantID: Int?
128+
public var abTestVariantID: Int?
129129

130130
/**
131131
The query string that will be searched, after
@@ -135,7 +135,7 @@ public struct SearchResponse {
135135
(see Query.advancedSyntax or Settings.advancedSyntax).
136136
- Returned only if Query.getRankingInfo is set to true.
137137
*/
138-
public let parsedQuery: String?
138+
public var parsedQuery: String?
139139

140140
/**
141141
A mapping of each facet name to the corresponding facet counts.
@@ -192,16 +192,16 @@ public struct SearchResponse {
192192
/**
193193
Returned only by the EndpointSearch.browse method.
194194
*/
195-
public let cursor: Cursor?
195+
public var cursor: Cursor?
196196

197-
public let indexName: IndexName?
197+
public var indexName: IndexName?
198198

199-
public let processed: Bool?
199+
public var processed: Bool?
200200

201201
/**
202202
Identifies the query uniquely. Can be used by InsightsEvent.
203203
*/
204-
public let queryID: QueryID?
204+
public var queryID: QueryID?
205205

206206
/**
207207
A mapping of each facet name to the corresponding facet counts for hierarchical facets.
@@ -223,10 +223,16 @@ public struct SearchResponse {
223223
/**
224224
Meta-information as to how the query was processed.
225225
*/
226-
public let explain: Explain?
227-
226+
public var explain: Explain?
227+
228+
public init(hits: [Hit<JSON>] = []) {
229+
self.hits = hits
230+
}
231+
228232
}
229233

234+
extension SearchResponse: Builder {}
235+
230236
public extension SearchResponse {
231237

232238
func extractHits<T: Decodable>() throws -> [T] {

0 commit comments

Comments
 (0)