No separate method is provided to do search in Parse document. Following code can be used to search a column .
PFQuery *query = [PFUser query];
[query whereKey:@"username" hasPrefix:searchText.lowercaseString];
[query whereKey:@"objectId" notEqualTo:[[PFUser currentUser] objectId]];
[query findObjectsInBackgroundWithBlock:^(NSArray *result, NSError *error){
callback(result, error);
}];
// Above code is searching for users(other than the logged in user) based on their username
Above, before providing searchText to query I am converting it to lower case as parse does not support case sensitive search. So, either save usernames as lower case string or as upper case string. Then only this search method can be used.
One more condition is provided in PFQuery that can help in search. "containsString" can also be used for search as follow:
PFQuery *query = [PFUser query];
[query whereKey:@"username" containsString:searchText.lowercaseString];
[query whereKey:@"objectId" notEqualTo:[[PFUser currentUser] objectId]];
[query findObjectsInBackgroundWithBlock:^(NSArray *result, NSError *error){
callback(result, error);
}];
0 Comment(s)