Skip to content

Full Text Search Query #1196

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Parse/Internal/Query/PFQueryConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ extern NSString *const PFQueryKeyNearSphere;
extern NSString *const PFQueryKeyWithin;
extern NSString *const PFQueryKeyGeoWithin;
extern NSString *const PFQueryKeyGeoIntersects;
extern NSString *const PFQueryKeyText;
extern NSString *const PFQueryKeyRegex;
extern NSString *const PFQueryKeyExists;
extern NSString *const PFQueryKeyInQuery;
Expand All @@ -39,6 +40,8 @@ extern NSString *const PFQueryOptionKeyMaxDistance;
extern NSString *const PFQueryOptionKeyBox;
extern NSString *const PFQueryOptionKeyPolygon;
extern NSString *const PFQueryOptionKeyPoint;
extern NSString *const PFQueryOptionKeySearch;
extern NSString *const PFQueryOptionKeyTerm;
extern NSString *const PFQueryOptionKeyRegexOptions;

NS_ASSUME_NONNULL_END
3 changes: 3 additions & 0 deletions Parse/Internal/Query/PFQueryConstants.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
NSString *const PFQueryKeyGeoWithin = @"$geoWithin";
NSString *const PFQueryKeyGeoIntersects = @"$geoIntersects";
NSString *const PFQueryKeyRegex = @"$regex";
NSString *const PFQueryKeyText = @"$text";
NSString *const PFQueryKeyExists = @"$exists";
NSString *const PFQueryKeyInQuery = @"$inQuery";
NSString *const PFQueryKeyNotInQuery = @"$notInQuery";
Expand All @@ -37,4 +38,6 @@
NSString *const PFQueryOptionKeyBox = @"$box";
NSString *const PFQueryOptionKeyPolygon = @"$polygon";
NSString *const PFQueryOptionKeyPoint = @"$point";
NSString *const PFQueryOptionKeySearch = @"$search";
NSString *const PFQueryOptionKeyTerm = @"$term";
NSString *const PFQueryOptionKeyRegexOptions = @"$options";
15 changes: 13 additions & 2 deletions Parse/PFQuery.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ typedef void (^PFQueryArrayResultBlock)(NSArray<PFGenericObject> *_Nullable obje

/**
Make the query include `PFObject`s that have a reference stored at the provided keys.

@param keys The keys to load child `PFObject`s for.

@return The same instance of `PFQuery` as the receiver. This allows method chaining.
*/
- (instancetype)includeKeys:(NSArray<NSString *> *)keys;
Expand Down Expand Up @@ -196,6 +196,17 @@ typedef void (^PFQueryArrayResultBlock)(NSArray<PFGenericObject> *_Nullable obje
*/
- (instancetype)whereKey:(NSString *)key notEqualTo:(id)object;

/**
Add a constraint for finding string values that contain a provided
string using Full Text Search

@param key The key to be constrained.
@param text the substring that the value must contain.

@return The same instance of `PFQuery` as the receiver. This allows method chaining.
*/
- (instancetype)whereKey:(NSString *)key matchesText:(NSString *)text;

/**
Add a constraint to the query that requires a particular key's object
to be contained in the provided array.
Expand Down
5 changes: 5 additions & 0 deletions Parse/PFQuery.m
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,11 @@ - (instancetype)whereKey:(NSString *)key polygonContains:(PFGeoPoint *)point {
return [self whereKey:key condition:PFQueryKeyGeoIntersects object:dictionary];
}

- (instancetype)whereKey:(NSString *)key matchesText:(NSString *)text {
NSDictionary *dictionary = @{ PFQueryOptionKeySearch : @{PFQueryOptionKeyTerm : text} };
return [self whereKey:key condition:PFQueryKeyText object:dictionary];
}

- (instancetype)whereKey:(NSString *)key matchesRegex:(NSString *)regex {
return [self whereKey:key condition:PFQueryKeyRegex object:regex];
}
Expand Down
10 changes: 8 additions & 2 deletions Tests/Unit/QueryUnitTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -419,20 +419,26 @@ - (void)testWhereKeyWithinPolygon {
PFGeoPoint *geoPoint1 = [PFGeoPoint geoPointWithLatitude:10.0 longitude:20.0];
PFGeoPoint *geoPoint2 = [PFGeoPoint geoPointWithLatitude:20.0 longitude:30.0];
PFGeoPoint *geoPoint3 = [PFGeoPoint geoPointWithLatitude:30.0 longitude:40.0];

PFQuery *query = [PFQuery queryWithClassName:@"a"];
[query whereKey:@"yolo" withinPolygon:@[geoPoint1, geoPoint2, geoPoint3]];
XCTAssertEqualObjects(query.state.conditions, (@{ @"yolo" : @{@"$geoWithin" : @{@"$polygon" : @[ geoPoint1, geoPoint2, geoPoint3 ]}} }));
}

- (void)testWhereKeyPolygonContains {
PFGeoPoint *geoPoint = [PFGeoPoint geoPointWithLatitude:10.0 longitude:20.0];

PFQuery *query = [PFQuery queryWithClassName:@"a"];
[query whereKey:@"yolo" polygonContains:geoPoint];
XCTAssertEqualObjects(query.state.conditions, (@{ @"yolo" : @{@"$geoIntersects" : @{@"$point" : geoPoint}} }));
}

- (void)testWhereKeyMatchesText {
PFQuery *query = [PFQuery queryWithClassName:@"a"];
[query whereKey:@"yolo" matchesText:@"yarr"];
XCTAssertEqualObjects(query.state.conditions, (@{ @"yolo" : @{@"$text" : @{@"$search" : @{@"$term" : @"yarr"} }} }));
}

- (void)testWhereKeyMatchesRegex {
PFQuery *query = [PFQuery queryWithClassName:@"a"];
[query whereKey:@"yolo" matchesRegex:@"yarr"];
Expand Down