是否可以在其中一个查询中使用位置进行复合查询。我需要在3英里范围内发布帖子,并且每个人都可以看到一些具有特定布尔值的帖子。
问题是,当我尝试这样做时,它给了我一个解析异常,说“不支持地理查询或”
答案 0 :(得分:0)
所以我正在做的事情。我们有一个'Blast'类和一个'Activity'类。爆炸是附近地理定位的物品。活动存储关注者和关注者的关系。我在网上其他地方发现的技巧(我记不住了)是将地理查询包装在另一个查询中,然后一切都很好。在我们的例子中,'nearbyItemsQueryWrapped'有效地'包装''nearbyItemsQuery',这样我们就可以做一些与你正在做的事情非常相似的事情。
这仍然不是满足我们特定需求的完美解决方案,因为它似乎与“当前”用户的项目存在问题 - 但它非常接近,可能会达到您的目标。
PFGeoPoint *point = [PFGeoPoint geoPointWithLatitude:location.latitude longitude:location.longitude];
PFQuery *followeesQuery = [PFQuery queryWithClassName:kActivityObjectClassNameKey];
[followeesQuery whereKey:kActivityFromUserKey equalTo:[PFUser currentUser]];
[followeesQuery whereKey:kActivityTypeKey equalTo:kActivityTypeFollow];
[followeesQuery whereKey:kActivityDeletedKey notEqualTo:@YES];
PFQuery *nearbyItemsQuery = [PFQuery queryWithClassName:kBlastObjectClassNameKey];
[nearbyItemsQuery whereKey:kBlastLocationKey nearGeoPoint:point withinKilometers:kItemSearchRadius_Largest_Kilometers];
[nearbyItemsQuery whereKey:kBlastFromUserKey doesNotMatchKey:kActivityToUserKey inQuery:followeesQuery];
PFQuery *nearbyItemsQueryWrapped = [PFQuery queryWithClassName:kBlastObjectClassNameKey];
[nearbyItemsQueryWrapped whereKey:kBlastFromUserKey matchesKey:kBlastFromUserKey inQuery:nearbyItemsQuery];
PFQuery *followersItemQuery = [PFQuery queryWithClassName:kBlastObjectClassNameKey];
[followersItemQuery whereKey:kBlastFromUserKey matchesKey:kActivityToUserKey inQuery:followeesQuery];
NSMutableArray *queryArray = NSMutableArray.new;
[queryArray addObject:followersItemQuery];
[queryArray addObject:nearbyItemsQueryWrapped];
PFQuery* compoundQuery = [PFQuery orQueryWithSubqueries:queryArray];
[compoundQuery includeKey:kBlastFromUserKey];
[compoundQuery includeKey:kBlastCategoryKey];
// unexpired only
[compoundQuery whereKey:kBlastEndDateKey greaterThanOrEqualTo:[NSDate date]];
// order them chronologically
[compoundQuery orderByDescending:kBlastStartDateKey];
// set up paging
compoundQuery.limit = kQueryLimit;
compoundQuery.skip = 0;
// we don't want deleted items
[compoundQuery whereKey:kBlastDeletedKey equalTo:@NO];
[compoundQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {