Skip to content

Commit 11b2f2b

Browse files
author
William Templeton
committed
Removal of highlight from SearchResultHit to allow for successful decoding
1 parent b2d390b commit 11b2f2b

File tree

1 file changed

+2
-19
lines changed

1 file changed

+2
-19
lines changed

Sources/Typesense/Models/SearchResultHit.swift

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,15 @@ public struct SearchResultHit<T: Codable>: Codable {
1313

1414
/** (Deprecated) Contains highlighted portions of the search fields */
1515
public var highlights: [SearchHighlight]?
16-
/** JSON data representation of the highlight field */
17-
private var highlightData: Data?
18-
/** Highlighted version of the matching document */
19-
public var highlight: [String: Any]?
20-
/** Can be any key-value pair */
2116
public var document: T?
2217
public var textMatch: Int64?
23-
/** Can be any key-value pair */
2418
public var geoDistanceMeters: [String:Int]?
2519
/** Distance between the query vector and matching document&#x27;s vector value */
2620
public var vectorDistance: Float?
2721

28-
public init(highlights: [SearchHighlight]? = nil, highlight: Data? = nil, document: T? = nil, textMatch: Int64? = nil, geoDistanceMeters: [String:Int]? = nil, vectorDistance: Float? = nil) {
22+
public init(highlights: [SearchHighlight]? = nil, document: T? = nil, textMatch: Int64? = nil, geoDistanceMeters: [String:Int]? = nil, vectorDistance: Float? = nil) {
2923
self.highlights = highlights
30-
self.highlightData = highlight
31-
self.highlight = SearchResultHit.decodeHighlight(data: highlightData)
24+
// self.highlightData = highlight
3225
self.document = document
3326
self.textMatch = textMatch
3427
self.geoDistanceMeters = geoDistanceMeters
@@ -38,25 +31,15 @@ public struct SearchResultHit<T: Codable>: Codable {
3831
public init(from decoder: Decoder) throws {
3932
let container: KeyedDecodingContainer<SearchResultHit<T>.CodingKeys> = try decoder.container(keyedBy: SearchResultHit<T>.CodingKeys.self)
4033
self.highlights = try container.decodeIfPresent([SearchHighlight].self, forKey: SearchResultHit<T>.CodingKeys.highlights)
41-
self.highlightData = try container.decodeIfPresent(Data.self, forKey: SearchResultHit<T>.CodingKeys.highlight)
42-
self.highlight = SearchResultHit.decodeHighlight(data: highlightData)
4334
self.document = try container.decodeIfPresent(T.self, forKey: SearchResultHit<T>.CodingKeys.document)
4435
self.textMatch = try container.decodeIfPresent(Int64.self, forKey: SearchResultHit<T>.CodingKeys.textMatch)
4536
self.geoDistanceMeters = try container.decodeIfPresent([String : Int].self, forKey: SearchResultHit<T>.CodingKeys.geoDistanceMeters)
4637
self.vectorDistance = try container.decodeIfPresent(Float.self, forKey: SearchResultHit<T>.CodingKeys.vectorDistance)
4738
}
4839

49-
private static func decodeHighlight(data: Data?) -> [String: Any]? {
50-
guard let data = data else { return nil }
51-
guard let object = try? JSONSerialization.jsonObject(with: data) else { return nil }
52-
guard let dictionary = object as? [String: Any] else { return nil }
53-
return dictionary
54-
}
55-
5640
public func encode(to encoder: Encoder) throws {
5741
var container = encoder.container(keyedBy: CodingKeys.self)
5842
try container.encode(highlights, forKey: CodingKeys.highlights)
59-
try container.encode(highlightData, forKey: CodingKeys.highlight)
6043
try container.encode(document, forKey: CodingKeys.document)
6144
try container.encode(textMatch, forKey: CodingKeys.textMatch)
6245
try container.encode(geoDistanceMeters, forKey: CodingKeys.geoDistanceMeters)

0 commit comments

Comments
 (0)