<commit_before>//
//  Hit.swift
//  
//
//  Created by <NAME> on 13.03.2020.
//

import Foundation

/// Wraps a generic hit object with its meta information

public struct Hit<T: Codable> {
  
  public let objectID: String
  public let object: T
  public let snippetResult: TreeModel<SnippetResult>?
  public let highlightResult: TreeModel<HighlightResult>?
  public let rankingInfo: RankingInfo?
  //    public let geolocation: Place.Geolocation?
  
  public init(objectID: String, object: T) {
    self.objectID = objectID
    self.object = object
    self.snippetResult = nil
    self.highlightResult = nil
    self.rankingInfo = nil
    //        self.geolocation = nil
  }
  
}

extension Hit: Codable {
  
  enum CodingKeys: String, CodingKey {
    case objectID
    case snippetResult = "_snippetResult"
    case highlightResult = "_highlightResult"
    case rankingInfo = "_rankingInfo"
    //        case geolocation = "_geoloc"
  }
  
  public init(from decoder: Decoder) throws {
    self.object = try T(from: decoder)
    let container = try decoder.container(keyedBy: CodingKeys.self)
    self.objectID = try container.decode(String.self, forKey: .objectID)
    self.snippetResult = try container.decodeIfPresent(TreeModel<SnippetResult>.self, forKey: .snippetResult)
    self.highlightResult = try container.decodeIfPresent(TreeModel<HighlightResult>.self, forKey: .highlightResult)
    self.rankingInfo = try container.decodeIfPresent(RankingInfo.self, forKey: .rankingInfo)
    //        self.geolocation = try container.decodeIfPresent(Place.Geolocation.self, forKey: .geolocation)
  }
  
  public func encode(to encoder: Encoder) throws {
    var keyedContainer = encoder.container(keyedBy: CodingKeys.self)
    try keyedContainer.encode(objectID, forKey: .objectID)
    var valueContainter = encoder.singleValueContainer()
    try valueContainter.encode(object)
  }
  
}

extension Hit {
  
  /// Snippet result for an attribute of a hit.
  
  public struct SnippetResult: Codable, Hashable {<commit_msg>Fix Hit encoding<commit_after>//
//  Hit.swift
//  
//
//  Created by <NAME> on 13.03.2020.
//

import Foundation

/// Wraps a generic hit object with its meta information

public struct Hit<T: Codable> {
  
  public let objectID: String
  public let object: T
  public let snippetResult: TreeModel<SnippetResult>?
  public let highlightResult: TreeModel<HighlightResult>?
  public let rankingInfo: RankingInfo?
  //    public let geolocation: Place.Geolocation?
  
  public init(objectID: String, object: T) {
    self.objectID = objectID
    self.object = object
    self.snippetResult = nil
    self.highlightResult = nil
    self.rankingInfo = nil
    //        self.geolocation = nil
  }
  
}

extension Hit: Codable {
  
  enum CodingKeys: String, CodingKey {
    case objectID
    case snippetResult = "_snippetResult"
    case highlightResult = "_highlightResult"
    case rankingInfo = "_rankingInfo"
    //        case geolocation = "_geoloc"
  }
  
  public init(from decoder: Decoder) throws {
    self.object = try T(from: decoder)
    let container = try decoder.container(keyedBy: CodingKeys.self)
    self.objectID = try container.decode(String.self, forKey: .objectID)
    self.snippetResult = try container.decodeIfPresent(TreeModel<SnippetResult>.self, forKey: .snippetResult)
    self.highlightResult = try container.decodeIfPresent(TreeModel<HighlightResult>.self, forKey: .highlightResult)
    self.rankingInfo = try container.decodeIfPresent(RankingInfo.self, forKey: .rankingInfo)
    //        self.geolocation = try container.decodeIfPresent(Place.Geolocation.self, forKey: .geolocation)
  }
  
  public func encode(to encoder: Encoder) throws {
    var keyedContainer = encoder.container(keyedBy: CodingKeys.self)
    try keyedContainer.encode(objectID, forKey: .objectID)
    try object.encode(to: encoder)
  }
  
}

extension Hit {
  
  /// Snippet result for an attribute of a hit.
  
  public struct SnippetResult: Codable, Hashable {
{'fraction_non_alphanumeric': 0.09353059177532598, 'fraction_numerical': 0.004012036108324975, 'mean_word_length': 3.4769921436588103, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3624917', 'n_tokens_mistral': 1264, 'n_tokens_neox': 1211, 'n_words': 314}