|
| 1 | +// Copyright 2025 Google LLC |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +#if SWIFT_PACKAGE |
| 16 | + @_exported import FirebaseFirestoreInternalWrapper |
| 17 | +#else |
| 18 | + @_exported import FirebaseFirestoreInternal |
| 19 | +#endif // SWIFT_PACKAGE |
| 20 | + |
| 21 | +import Foundation |
| 22 | + |
| 23 | +public struct FindNearestOptions { |
| 24 | + let field: Field |
| 25 | + let vectorValue: [VectorValue] |
| 26 | + let distanceMeasure: DistanceMeasure |
| 27 | + let limit: Int? |
| 28 | + let distanceField: String? |
| 29 | +} |
| 30 | + |
| 31 | +public struct DistanceMeasure: Sendable, Equatable, Hashable { |
| 32 | + enum Kind: String { |
| 33 | + case euclidean |
| 34 | + case cosine |
| 35 | + case dotProduct = "dot_product" |
| 36 | + } |
| 37 | + |
| 38 | + public static var euclidean: DistanceMeasure { |
| 39 | + return self.init(kind: .euclidean) |
| 40 | + } |
| 41 | + |
| 42 | + public static var cosine: DistanceMeasure { |
| 43 | + return self.init(kind: .cosine) |
| 44 | + } |
| 45 | + |
| 46 | + public static var dotProduct: DistanceMeasure { |
| 47 | + return self.init(kind: .dotProduct) |
| 48 | + } |
| 49 | + |
| 50 | + /// Returns the raw string representation of the `DistanceMeasure` value. |
| 51 | + public let rawValue: String |
| 52 | + |
| 53 | + init(kind: Kind) { |
| 54 | + rawValue = kind.rawValue |
| 55 | + } |
| 56 | + |
| 57 | + public init(rawValue: String) { |
| 58 | + if Kind(rawValue: rawValue) == nil { |
| 59 | + // impl |
| 60 | + } |
| 61 | + self.rawValue = rawValue |
| 62 | + } |
| 63 | +} |
0 commit comments