Skip to content

Commit 12f53ec

Browse files
dplewismontymxb
authored andcommitted
Full Text Search Query (#1196)
* Full Text Search Query * documentation
1 parent 98ba23c commit 12f53ec

File tree

5 files changed

+32
-4
lines changed

5 files changed

+32
-4
lines changed

Parse/Internal/Query/PFQueryConstants.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ extern NSString *const PFQueryKeyNearSphere;
2323
extern NSString *const PFQueryKeyWithin;
2424
extern NSString *const PFQueryKeyGeoWithin;
2525
extern NSString *const PFQueryKeyGeoIntersects;
26+
extern NSString *const PFQueryKeyText;
2627
extern NSString *const PFQueryKeyRegex;
2728
extern NSString *const PFQueryKeyExists;
2829
extern NSString *const PFQueryKeyInQuery;
@@ -39,6 +40,8 @@ extern NSString *const PFQueryOptionKeyMaxDistance;
3940
extern NSString *const PFQueryOptionKeyBox;
4041
extern NSString *const PFQueryOptionKeyPolygon;
4142
extern NSString *const PFQueryOptionKeyPoint;
43+
extern NSString *const PFQueryOptionKeySearch;
44+
extern NSString *const PFQueryOptionKeyTerm;
4245
extern NSString *const PFQueryOptionKeyRegexOptions;
4346

4447
NS_ASSUME_NONNULL_END

Parse/Internal/Query/PFQueryConstants.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
NSString *const PFQueryKeyGeoWithin = @"$geoWithin";
2323
NSString *const PFQueryKeyGeoIntersects = @"$geoIntersects";
2424
NSString *const PFQueryKeyRegex = @"$regex";
25+
NSString *const PFQueryKeyText = @"$text";
2526
NSString *const PFQueryKeyExists = @"$exists";
2627
NSString *const PFQueryKeyInQuery = @"$inQuery";
2728
NSString *const PFQueryKeyNotInQuery = @"$notInQuery";
@@ -37,4 +38,6 @@
3738
NSString *const PFQueryOptionKeyBox = @"$box";
3839
NSString *const PFQueryOptionKeyPolygon = @"$polygon";
3940
NSString *const PFQueryOptionKeyPoint = @"$point";
41+
NSString *const PFQueryOptionKeySearch = @"$search";
42+
NSString *const PFQueryOptionKeyTerm = @"$term";
4043
NSString *const PFQueryOptionKeyRegexOptions = @"$options";

Parse/PFQuery.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ typedef void (^PFQueryArrayResultBlock)(NSArray<PFGenericObject> *_Nullable obje
9696

9797
/**
9898
Make the query include `PFObject`s that have a reference stored at the provided keys.
99-
99+
100100
@param keys The keys to load child `PFObject`s for.
101-
101+
102102
@return The same instance of `PFQuery` as the receiver. This allows method chaining.
103103
*/
104104
- (instancetype)includeKeys:(NSArray<NSString *> *)keys;
@@ -196,6 +196,17 @@ typedef void (^PFQueryArrayResultBlock)(NSArray<PFGenericObject> *_Nullable obje
196196
*/
197197
- (instancetype)whereKey:(NSString *)key notEqualTo:(id)object;
198198

199+
/**
200+
Add a constraint for finding string values that contain a provided
201+
string using Full Text Search
202+
203+
@param key The key to be constrained.
204+
@param text the substring that the value must contain.
205+
206+
@return The same instance of `PFQuery` as the receiver. This allows method chaining.
207+
*/
208+
- (instancetype)whereKey:(NSString *)key matchesText:(NSString *)text;
209+
199210
/**
200211
Add a constraint to the query that requires a particular key's object
201212
to be contained in the provided array.

Parse/PFQuery.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,11 @@ - (instancetype)whereKey:(NSString *)key polygonContains:(PFGeoPoint *)point {
311311
return [self whereKey:key condition:PFQueryKeyGeoIntersects object:dictionary];
312312
}
313313

314+
- (instancetype)whereKey:(NSString *)key matchesText:(NSString *)text {
315+
NSDictionary *dictionary = @{ PFQueryOptionKeySearch : @{PFQueryOptionKeyTerm : text} };
316+
return [self whereKey:key condition:PFQueryKeyText object:dictionary];
317+
}
318+
314319
- (instancetype)whereKey:(NSString *)key matchesRegex:(NSString *)regex {
315320
return [self whereKey:key condition:PFQueryKeyRegex object:regex];
316321
}

Tests/Unit/QueryUnitTests.m

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,20 +419,26 @@ - (void)testWhereKeyWithinPolygon {
419419
PFGeoPoint *geoPoint1 = [PFGeoPoint geoPointWithLatitude:10.0 longitude:20.0];
420420
PFGeoPoint *geoPoint2 = [PFGeoPoint geoPointWithLatitude:20.0 longitude:30.0];
421421
PFGeoPoint *geoPoint3 = [PFGeoPoint geoPointWithLatitude:30.0 longitude:40.0];
422-
422+
423423
PFQuery *query = [PFQuery queryWithClassName:@"a"];
424424
[query whereKey:@"yolo" withinPolygon:@[geoPoint1, geoPoint2, geoPoint3]];
425425
XCTAssertEqualObjects(query.state.conditions, (@{ @"yolo" : @{@"$geoWithin" : @{@"$polygon" : @[ geoPoint1, geoPoint2, geoPoint3 ]}} }));
426426
}
427427

428428
- (void)testWhereKeyPolygonContains {
429429
PFGeoPoint *geoPoint = [PFGeoPoint geoPointWithLatitude:10.0 longitude:20.0];
430-
430+
431431
PFQuery *query = [PFQuery queryWithClassName:@"a"];
432432
[query whereKey:@"yolo" polygonContains:geoPoint];
433433
XCTAssertEqualObjects(query.state.conditions, (@{ @"yolo" : @{@"$geoIntersects" : @{@"$point" : geoPoint}} }));
434434
}
435435

436+
- (void)testWhereKeyMatchesText {
437+
PFQuery *query = [PFQuery queryWithClassName:@"a"];
438+
[query whereKey:@"yolo" matchesText:@"yarr"];
439+
XCTAssertEqualObjects(query.state.conditions, (@{ @"yolo" : @{@"$text" : @{@"$search" : @{@"$term" : @"yarr"} }} }));
440+
}
441+
436442
- (void)testWhereKeyMatchesRegex {
437443
PFQuery *query = [PFQuery queryWithClassName:@"a"];
438444
[query whereKey:@"yolo" matchesRegex:@"yarr"];

0 commit comments

Comments
 (0)