简体   繁体   中英

Parse.com user search without regex

I have an app where I have users with a user name and a spot for their real name. I also allow users to query to find other users. Currently my query looks like this:

PFQuery *userQuery = [PFUser query];
[userQuery whereKey:kCPUserName containsString:[searchText lowercaseString]];

PFQuery *userRealNameQuery = [PFUser query];
[usernameQuery whereKey:kCPUserFullName containsString: searchText];

PFQuery *userRealNameWithCapsQuery = [PFUser query];
[userRealNameWithCapsQuery whereKey:kCPUserFullName containsString:[searchText capitalizedString]];

PFQuery *userRealNameWithLowerQuery = [PFUser query];
[userRealNameWithLowerQuery whereKey:kCPUserFullName containsString:[searchText lowercaseString]];

PFQuery *finalQuery = [PFQuery orQueryWithSubqueries:@[userQuery, userRealNameQuery, userRealNameWithCapsQuery, userRealNameWithLowerQuery]];

This works great, returning a list of users likely to match the searchText . However, I've become aware that containsString uses regex, thus if I have many users searching at the same time I quickly run into the 80 regex queries / min limitation in parse. Using hasPrefix: also uses regex. The only query I can think of would be to use the equalTo: method, but that would mean that a user must know exactly who they are looking for and how to spell their names (either user or real).

Any suggestions?

My final solution to this problem was to create a separate field, call it combined_names. This field is a concatenation of the real and user names (all lowercase). I can then do a single regex call on this and get the same results. While not removing all regex calls, it goes from 4 calls to 1.

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