Skip to content

Commit a7b8ef7

Browse files
Merge d9eea7a into 72b55e2
2 parents 72b55e2 + d9eea7a commit a7b8ef7

File tree

15 files changed

+358
-1
lines changed

15 files changed

+358
-1
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2024 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+
#import <FirebaseFirestoreInternal/FIRDistanceMeasure.h>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2024 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+
#import <FirebaseFirestoreInternal/FIRFindNearestOptions.h>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2024 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+
#import <FirebaseFirestoreInternal/FIRVectorValue.h>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//
2+
// FIRFirestoreDistanceMeasure.h
3+
// FirebaseFirestoreInternal
4+
//
5+
// Created by Mark Duckworth on 7/25/24.
6+
//
7+
8+
#import <Foundation/Foundation.h>
9+
10+
typedef NS_ENUM(NSUInteger, FIRDistanceMeasure) {
11+
FIRDistanceMeasureCosine,
12+
FIRDistanceMeasureEuclidean,
13+
FIRDistanceMeasureDotProduct
14+
} NS_SWIFT_NAME(FirestoreDistanceMeasure);

Firestore/Source/Public/FirebaseFirestore/FIRFieldPath.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ NS_SWIFT_NAME(FieldPath)
3636
* @param fieldNames A list of field names.
3737
* @return A `FieldPath` that points to a field location in a document.
3838
*/
39-
- (instancetype)initWithFields:(NSArray<NSString *> *)fieldNames NS_SWIFT_NAME(init(_:));
39+
- (instancetype)initWithFields:(NSArray<NSString *> *)fieldNames
40+
NS_SWIFT_NAME(init(_:)) NS_DESIGNATED_INITIALIZER;
4041

4142
/**
4243
* A special sentinel `FieldPath` to refer to the ID of a document. It can be used in queries to
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//
2+
// FIRFindNearestOptions.h
3+
// FirebaseFirestoreInternal
4+
//
5+
// Created by Mark Duckworth on 7/25/24.
6+
//
7+
#import <Foundation/Foundation.h>
8+
9+
#import "FIRFieldPath.h"
10+
11+
@class FIRAggregateQuery;
12+
@class FIRAggregateField;
13+
@class FIRFieldPath;
14+
@class FIRFirestore;
15+
@class FIRFilter;
16+
@class FIRQuerySnapshot;
17+
@class FIRDocumentSnapshot;
18+
@class FIRVectorQuery;
19+
20+
NS_ASSUME_NONNULL_BEGIN
21+
22+
NS_SWIFT_NAME(FindNearestOptions)
23+
@interface FIRFindNearestOptions : NSObject
24+
@property(nonatomic, readonly) FIRFieldPath *distanceResultFieldPath;
25+
@property(nonatomic, readonly) NSNumber *distanceThreshold NS_REFINED_FOR_SWIFT;
26+
27+
- (nonnull instancetype)init NS_DESIGNATED_INITIALIZER;
28+
29+
- (nonnull FIRFindNearestOptions *)optionsWithDistanceResultFieldPath:
30+
(FIRFieldPath *)distanceResultFieldPath;
31+
32+
- (nonnull FIRFindNearestOptions *)optionsWithDistanceThreshold:(NSNumber *)distanceThreshold
33+
NS_REFINED_FOR_SWIFT;
34+
35+
@end
36+
37+
NS_ASSUME_NONNULL_END

Firestore/Source/Public/FirebaseFirestore/FIRQuery.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
#import <Foundation/Foundation.h>
1818

19+
#import "FIRDistanceMeasure.h"
20+
#import "FIRFindNearestOptions.h"
1921
#import "FIRFirestoreSource.h"
2022
#import "FIRListenerRegistration.h"
2123
#import "FIRSnapshotListenOptions.h"
@@ -27,6 +29,8 @@
2729
@class FIRFilter;
2830
@class FIRQuerySnapshot;
2931
@class FIRDocumentSnapshot;
32+
@class FIRVectorQuery;
33+
@class FIRVectorValue;
3034

3135
NS_ASSUME_NONNULL_BEGIN
3236

@@ -49,6 +53,13 @@ NS_SWIFT_NAME(Query)
4953
/** The `Firestore` instance that created this query (useful for performing transactions, etc.). */
5054
@property(nonatomic, strong, readonly) FIRFirestore *firestore;
5155

56+
- (nonnull FIRVectorQuery *)findNearestWithFieldPath:(nonnull FIRFieldPath *)fieldPath
57+
queryVectorValue:(nonnull FIRVectorValue *)queryVectorValue
58+
limit:(int64_t)limit
59+
distanceMeasure:(FIRDistanceMeasure)distanceMeasure
60+
options:(nonnull FIRFindNearestOptions *)options
61+
NS_REFINED_FOR_SWIFT;
62+
5263
#pragma mark - Retrieving Data
5364
/**
5465
* Reads the documents matching this query.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//
2+
// FIRVectorQuery.h
3+
// FirebaseFirestoreInternal
4+
//
5+
// Created by Mark Duckworth on 7/25/24.
6+
//
7+
#import <Foundation/Foundation.h>
8+
9+
#import "FIRVectorQuerySnapshot.h"
10+
#import "FIRVectorSource.h"
11+
12+
@class FIRAggregateQuery;
13+
@class FIRAggregateField;
14+
@class FIRFieldPath;
15+
@class FIRFirestore;
16+
@class FIRFilter;
17+
@class FIRVectorQuerySnapshot;
18+
@class FIRDocumentSnapshot;
19+
@class FIRVectorQuery;
20+
21+
NS_ASSUME_NONNULL_BEGIN
22+
23+
NS_SWIFT_NAME(VectorQuery)
24+
@interface FIRVectorQuery : NSObject
25+
26+
@property(nonatomic, strong, readonly) FIRQuery *query;
27+
28+
/**
29+
* Executes this query.
30+
*
31+
* @param source The source from which to acquire the VectorQuery results.
32+
* @param completion a block to execute once the results have been successfully read.
33+
* snapshot will be `nil` only if error is `non-nil`.
34+
*/
35+
- (void)getDocumentsWithSource:(FIRVectorSource)source
36+
completion:(void (^)(FIRVectorQuerySnapshot *_Nullable snapshot,
37+
NSError *_Nullable error))completion NS_REFINED_FOR_SWIFT;
38+
39+
@end
40+
41+
NS_ASSUME_NONNULL_END
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//
2+
// FIRVectorQuerySnapshot.h
3+
// FirebaseFirestoreInternal
4+
//
5+
// Created by Mark Duckworth on 7/25/24.
6+
//
7+
#import <Foundation/Foundation.h>
8+
9+
NS_ASSUME_NONNULL_BEGIN
10+
11+
@class FIRVectorQuery;
12+
@class FIRAggregateQuery;
13+
@class FIRAggregateField;
14+
@class FIRFieldPath;
15+
@class FIRFirestore;
16+
@class FIRFilter;
17+
@class FIRQuerySnapshot;
18+
@class FIRDocumentSnapshot;
19+
20+
NS_SWIFT_NAME(VectorQuerySnapshot)
21+
@interface FIRVectorQuerySnapshot : NSObject
22+
@property(nonatomic, strong, readonly) FIRVectorQuery *query;
23+
@property(nonatomic, strong, readonly) FIRSnapshotMetadata *metadata;
24+
@property(nonatomic, readonly, getter=isEmpty) BOOL empty;
25+
@property(nonatomic, readonly) NSInteger count;
26+
@property(nonatomic, strong, readonly) NSArray<FIRQueryDocumentSnapshot *> *documents;
27+
@property(nonatomic, strong, readonly) NSArray<FIRDocumentChange *> *documentChanges;
28+
- (NSArray<FIRDocumentChange *> *)documentChangesWithIncludeMetadataChanges:
29+
(BOOL)includeMetadataChanges NS_SWIFT_NAME(documentChanges(includeMetadataChanges:));
30+
31+
@end
32+
33+
NS_ASSUME_NONNULL_END
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//
2+
// FIRFirestoreVectorSource.h
3+
// FirebaseFirestoreInternal
4+
//
5+
// Created by Mark Duckworth on 7/25/24.
6+
//
7+
8+
#import <Foundation/Foundation.h>
9+
10+
typedef NS_ENUM(NSUInteger, FIRVectorSource) {
11+
FIRVectorSourceServer,
12+
} NS_SWIFT_NAME(VectorSource);
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//
2+
// FIeldPath+Expressible.swift
3+
// FirebaseFirestore
4+
//
5+
// Created by Mark Duckworth on 8/2/24.
6+
//
7+
8+
import Foundation
9+
10+
#if SWIFT_PACKAGE
11+
@_exported import FirebaseFirestoreInternalWrapper
12+
#else
13+
@_exported import FirebaseFirestoreInternal
14+
#endif // SWIFT_PACKAGE
15+
// extension FieldPath : ExpressibleByStringLiteral {
16+
// public required convenience init(stringLiteral: String) {
17+
// self.init([stringLiteral])
18+
// }
19+
// }
20+
21+
private protocol ExpressibleByStringLiteralFieldPath: ExpressibleByStringLiteral {
22+
init(_: [String])
23+
}
24+
25+
/**
26+
* An extension of VectorValue that implements the behavior of the Codable protocol.
27+
*
28+
* Note: this is implemented manually here because the Swift compiler can't synthesize these methods
29+
* when declaring an extension to conform to Codable.
30+
*/
31+
extension ExpressibleByStringLiteralFieldPath {
32+
public init(stringLiteral: String) {
33+
self.init([stringLiteral])
34+
}
35+
}
36+
37+
/** Extends VectorValue to conform to Codable. */
38+
extension FieldPath: ExpressibleByStringLiteralFieldPath {}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright 2024 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#if SWIFT_PACKAGE
18+
@_exported import FirebaseFirestoreInternalWrapper
19+
#else
20+
@_exported import FirebaseFirestoreInternal
21+
#endif // SWIFT_PACKAGE
22+
23+
public extension FindNearestOptions {
24+
var distanceThreshold: Double {
25+
return __distanceThreshold.doubleValue
26+
}
27+
28+
func withDistanceThreshold(_ distanceThreshold: Double) -> FindNearestOptions {
29+
return __withDistanceThreshold(NSNumber(value: distanceThreshold))
30+
}
31+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright 2024 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#if SWIFT_PACKAGE
18+
@_exported import FirebaseFirestoreInternalWrapper
19+
#else
20+
@_exported import FirebaseFirestoreInternal
21+
#endif // SWIFT_PACKAGE
22+
23+
public extension Query {
24+
func findNearest(fieldPath: FieldPath,
25+
queryVector: VectorValue,
26+
limit: Int64,
27+
distanceMeasure: FirestoreDistanceMeasure,
28+
options: FindNearestOptions = FindNearestOptions()) -> VectorQuery {
29+
fatalError("not implemented")
30+
}
31+
32+
func findNearest(fieldPath: FieldPath,
33+
queryVector: [Double],
34+
limit: Int64,
35+
distanceMeasure: FirestoreDistanceMeasure,
36+
options: FindNearestOptions = FindNearestOptions()) -> VectorQuery {
37+
fatalError("not implemented")
38+
}
39+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright 2024 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#if SWIFT_PACKAGE
18+
@_exported import FirebaseFirestoreInternalWrapper
19+
#else
20+
@_exported import FirebaseFirestoreInternal
21+
#endif // SWIFT_PACKAGE
22+
23+
public extension VectorQuery {
24+
func getDocuments(source: VectorSource) async throws -> VectorQuerySnapshot {
25+
fatalError("not implemented")
26+
}
27+
}

0 commit comments

Comments
 (0)