i have parse.com database. i have column in a table named "text". i have to find text with multiple keys matching with AND condition. i tried it all ways. i tried to use:
PFQuery *query=[PFQuery queryWithClassName:@"post"];
[query whereKey:@"text" containedIn:Array];
or
PFQuery *query=[PFQuery queryWithClassName:@"post"];
[query whereKey:@"text" containsAllObjectsInArray:Array];
or
PFQuery *query=[PFQuery queryWithClassName:@"post"];
for (NSString *str in filtersArray) {
[query whereKey:@"text" containsString:str];
}
but no one works. please guide me if parse sdks supports this or not totally? if yes how can i achieve the results. many thanks in advance :)
EIDT:
for example i have three entries in database as text:
"i have a data entry"
"i can not find something in data"
"how can i do this"
if pass "i" and "this" it should return entry (3)
if pass "i" and "data" it should return entry (1,2)
if pass "i" and "else" it should return nothing
The reason your query doesn't work is because Parse does not support having the same constraint (in this case 'containsString:') more than once on the same key.
So, what I would suggest is to query for a regular expression which will match all of your filter strings using - (instancetype)whereKey:(NSString *)key matchesRegex:(NSString *)regex
.
NSArray *qryStrings = @[str1, str2, str3, ....]; //strings you are trying to match
//string which will hold our regular expression
NSString *regexString = @"^"; //start off the regex
for (NSString *str in qryStrings) { //build the regex one filter at a time
regexString = [NSString stringWithFormat:@"%@(?=.*%@)", regexString, str];
}
regexString = [NSString stringWithFormat:@"%@.*$", regexString]; //finish off the regex
PFQuery *query = [PFQuery queryWithClassName:@"post"];
[query whereKey:@"text" matchesRegex:regexString];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
//objects array contains matching rows with matching strings
}
else {
NSLog(@"%@ %@", error, [error userInfo]);
}
}];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With