@@ -17,15 +17,15 @@ public struct RecommendHit: Codable, JSONEncodable {
17
17
public var rankingInfo : RecommendRankingInfo ?
18
18
public var distinctSeqID : Int ?
19
19
/// Recommendation score.
20
- public var score : Double
20
+ public var score : Double ?
21
21
22
22
public init (
23
23
objectID: String ,
24
24
highlightResult: [ String : RecommendHighlightResult ] ? = nil ,
25
25
snippetResult: [ String : RecommendSnippetResult ] ? = nil ,
26
26
rankingInfo: RecommendRankingInfo ? = nil ,
27
27
distinctSeqID: Int ? = nil ,
28
- score: Double
28
+ score: Double ? = nil
29
29
) {
30
30
self . objectID = objectID
31
31
self . highlightResult = highlightResult
@@ -72,10 +72,8 @@ public struct RecommendHit: Codable, JSONEncodable {
72
72
73
73
self . distinctSeqID = dictionary [ " distinctSeqID " ] ? . value as? Int
74
74
75
- guard let score = dictionary [ " score " ] ? . value as? Double else {
76
- throw GenericError ( description: " Failed to cast " )
77
- }
78
- self . score = score
75
+ self . score = dictionary [ " score " ] ? . value as? Double
76
+
79
77
for (key, value) in dictionary {
80
78
switch key {
81
79
case " objectID " , " highlightResult " , " snippetResult " , " rankingInfo " , " distinctSeqID " , " score " :
@@ -95,7 +93,7 @@ public struct RecommendHit: Codable, JSONEncodable {
95
93
try container. encodeIfPresent ( self . snippetResult, forKey: . snippetResult)
96
94
try container. encodeIfPresent ( self . rankingInfo, forKey: . rankingInfo)
97
95
try container. encodeIfPresent ( self . distinctSeqID, forKey: . distinctSeqID)
98
- try container. encode ( self . score, forKey: . score)
96
+ try container. encodeIfPresent ( self . score, forKey: . score)
99
97
var additionalPropertiesContainer = encoder. container ( keyedBy: String . self)
100
98
try additionalPropertiesContainer. encodeMap ( self . additionalProperties)
101
99
}
@@ -116,7 +114,7 @@ public struct RecommendHit: Codable, JSONEncodable {
116
114
)
117
115
self . rankingInfo = try container. decodeIfPresent ( RecommendRankingInfo . self, forKey: . rankingInfo)
118
116
self . distinctSeqID = try container. decodeIfPresent ( Int . self, forKey: . distinctSeqID)
119
- self . score = try container. decode ( Double . self, forKey: . score)
117
+ self . score = try container. decodeIfPresent ( Double . self, forKey: . score)
120
118
var nonAdditionalPropertyKeys = Set < String > ( )
121
119
nonAdditionalPropertyKeys. insert ( " objectID " )
122
120
nonAdditionalPropertyKeys. insert ( " _highlightResult " )
@@ -151,7 +149,7 @@ extension RecommendHit: Hashable {
151
149
hasher. combine ( self . snippetResult? . hashValue)
152
150
hasher. combine ( self . rankingInfo? . hashValue)
153
151
hasher. combine ( self . distinctSeqID? . hashValue)
154
- hasher. combine ( self . score. hashValue)
152
+ hasher. combine ( self . score? . hashValue)
155
153
hasher. combine ( self . additionalProperties. hashValue)
156
154
}
157
155
}
0 commit comments