Skip to content

Commit abb3ffc

Browse files
authored
Merge pull request #43 from NaifAlrashed/master
make search related container structs decodable
2 parents c62f417 + b63183a commit abb3ffc

File tree

7 files changed

+10
-19
lines changed

7 files changed

+10
-19
lines changed

Sources/Typesense/Models/DocumentIndexParameters.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ public struct DocumentIndexParameters: Codable {
1414
case dirtyValues = "dirty_values"
1515
}
1616

17-
}
17+
}

Sources/Typesense/Models/MultiSearchResult.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Foundation
99

1010

1111

12-
public struct MultiSearchResult<T: Codable>: Codable {
12+
public struct MultiSearchResult<T: Decodable>: Decodable {
1313

1414
public var results: [SearchResult<T>]
1515
public var conversation: SearchResultConversation?

Sources/Typesense/Models/PresetValue.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ public enum PresetValue: Codable {
2525
try singleCollectionSearch.encode(to: encoder)
2626
}
2727
}
28-
}
28+
}

Sources/Typesense/Models/SearchGroupedHit.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import Foundation
99
import AnyCodable
1010

11-
public struct SearchGroupedHit<T: Codable>: Codable {
11+
public struct SearchGroupedHit<T: Decodable>: Decodable {
1212

1313
public var found: Int?
1414
public var groupKey: [AnyCodable]

Sources/Typesense/Models/SearchResult.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Foundation
99

1010

1111

12-
public struct SearchResult<T: Codable>: Codable {
12+
public struct SearchResult<T: Decodable>: Decodable {
1313

1414
public var facetCounts: [FacetCounts]?
1515
/** The number of documents found */

Sources/Typesense/Models/SearchResultHit.swift

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Foundation
99

1010

1111

12-
public struct SearchResultHit<T: Codable>: Codable {
12+
public struct SearchResultHit<T: Decodable>: Decodable {
1313

1414
/** (Deprecated) Contains highlighted portions of the search fields */
1515
public var highlights: [SearchHighlight]?
@@ -36,15 +36,6 @@ public struct SearchResultHit<T: Codable>: Codable {
3636
self.geoDistanceMeters = try container.decodeIfPresent([String : Int].self, forKey: SearchResultHit<T>.CodingKeys.geoDistanceMeters)
3737
self.vectorDistance = try container.decodeIfPresent(Float.self, forKey: SearchResultHit<T>.CodingKeys.vectorDistance)
3838
}
39-
40-
public func encode(to encoder: Encoder) throws {
41-
var container = encoder.container(keyedBy: CodingKeys.self)
42-
try container.encode(highlights, forKey: CodingKeys.highlights)
43-
try container.encode(document, forKey: CodingKeys.document)
44-
try container.encode(textMatch, forKey: CodingKeys.textMatch)
45-
try container.encode(geoDistanceMeters, forKey: CodingKeys.geoDistanceMeters)
46-
try container.encode(vectorDistance, forKey: CodingKeys.vectorDistance)
47-
}
4839

4940
public enum CodingKeys: String, CodingKey {
5041
case highlights

get-models.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,22 @@ find . -name "MultiSearchParameters.swift" -exec sed -i '' 's/maxHits: OneOfMult
1818
find . -name "MultiSearchCollectionParameters.swift" -exec sed -i '' 's/maxHits: Any\?/maxHits: String\?/g' {} \;
1919

2020
# Add Generics to SearchResult
21-
find . -name "SearchResult.swift" -exec sed -i '' 's/SearchResult:/SearchResult<T: Codable>:/g' {} \;
21+
find . -name "SearchResult.swift" -exec sed -i '' 's/SearchResult:/SearchResult<T: Decodable>:/g' {} \;
2222
find . -name "SearchResult.swift" -exec sed -i '' 's/groupedHits: \[SearchGroupedHit\]\?/groupedHits: \[SearchGroupedHit<T>\]\?/g' {} \;
2323
find . -name "SearchResult.swift" -exec sed -i '' 's/hits: \[SearchResultHit\]\?/hits: \[SearchResultHit<T>\]\?/g' {} \;
2424

2525
# Add Generics to MultiSearchResult
2626
find . -name "MultiSearchResult.swift" -exec sed -i '' 's/results: \[SearchResult\]/results: \[SearchResult<T>\]/g' {} \;
27-
find . -name "MultiSearchResult.swift" -exec sed -i '' 's/MultiSearchResult:/MultiSearchResult<T: Codable>:/g' {} \;
27+
find . -name "MultiSearchResult.swift" -exec sed -i '' 's/MultiSearchResult:/MultiSearchResult<T: Decodable>:/g' {} \;
2828

2929
# Add Generics to SearchResultHit
30-
find . -name "SearchResultHit.swift" -exec sed -i '' 's/SearchResultHit:/SearchResultHit<T: Codable>:/g' {} \;
30+
find . -name "SearchResultHit.swift" -exec sed -i '' 's/SearchResultHit:/SearchResultHit<T: Decodable>:/g' {} \;
3131

3232
# Convert document parameter to a generic T
3333
find . -name "SearchResultHit.swift" -exec sed -i '' 's/document: \[String:Any\]\?/document: T?/g' {} \;
3434

3535
# Add Generics to SearchGroupedHit
36-
find . -name "SearchGroupedHit.swift" -exec sed -i '' 's/SearchGroupedHit:/SearchGroupedHit<T: Codable>:/g' {} \;
36+
find . -name "SearchGroupedHit.swift" -exec sed -i '' 's/SearchGroupedHit:/SearchGroupedHit<T: Decodable>:/g' {} \;
3737
find . -name "SearchGroupedHit.swift" -exec sed -i '' 's/hits: \[SearchResultHit\]/hits: \[SearchResultHit<T>\]/g' {} \;
3838

3939
# Convert matchedTokens to custom defined StringQuantum

0 commit comments

Comments
 (0)