[英]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 . 这很好用,返回可能与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.
但是,我已经知道containsString使用正则表达式,因此,如果有很多用户同时搜索,我很快就会遇到80个正则表达式查询/分钟限制。 Using hasPrefix: also uses regex.
使用hasPrefix:也使用正则表达式。 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).
我能想到的唯一查询是使用equalTo:方法,但这意味着用户必须确切知道他们要查找的人以及如何拼写他们的名字(用户名或真实名)。
Any suggestions? 有什么建议么?
My final solution to this problem was to create a separate field, call it combined_names. 我对此问题的最终解决方案是创建一个单独的字段,将其称为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.
虽然不删除所有正则表达式调用,但它从4个调用变为1个。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.