简体   繁体   中英

PFQuery returning objects where object's relation matches all conditions

Working on an iPhone app with Parse DB backend I'm trying to implement a search functionality using search tokens . I read Parse's white papers on scalable search, relations vs. pointers, documentation, various SO / Parse.com discussions, etc. - unfortunately couldn't find any similarity to my problem.

I'm using a class SearchToken where I'm storing unique sanitised tokens and I have a PFRelation *tokenRelation in related class Article ( every article can have multiple search tokens; every token can be related to multiple articles ).

I'm trying to form a query that finds all objects from Article class that contain all searched tokens (eg @"token1", @"token2" ). Unfortunately whereKey:containsAllObjectsInArray: doesn't work on PFRelation attributes which further complicates things for me.

An easy option would be to convert that PFRelation attribute to an array of pointers but I know that the number of associated tokens can exceed everywhere-mentioned limit of 100 objects so I'm bit hesitant here.

My question is: is there any other way of querying objects matching all conditions in related objects (via PFRelation ) or is there any better way of implementing tokenised search feature?

I'd use the array of pointers, because I assume there is a maximum number of tokens that can be set on one article. (AFAIK the limit is 1k Parse Docs ) Parse says it makes sense if you know the max number (eg postal codes). See Relationships in parse

If an array of pointers is not a possible solution for you, I'd solve the n:m relation with your own class (eg HasToken or TokenRelationship) instead of PFRelation (or Array of pointers).

@interface TokenRelationship : PFObject <PFSubclassing>
@property (nonatomic, strong) Article article;
@property (nonatomic, strong) SearchToken searchToken;
@end

Then perform a query on TokenRelationship with a subquery using whereKey:matchesQuery: .

Nevertheless you can reach the limit of 1k. So both solutions have their limits. I hope that parse introduces where-key constraints on forein-key pointers like: whereKey:@"searchToken.tokenString" equalTo:@"token1" or they do away with the 1k limit on sub/inner-queries. Otherwise n:m relation queries are likely to exceed the limit.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM