0

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 (e.g. @"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?

David Jirman
  • 1,216
  • 12
  • 25

1 Answers1

0

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 (e.g 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 (e.g. 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.

cakl
  • 390
  • 1
  • 3
  • 13