Search code examples
objective-carrayssearchkinvey

Kinvey search function


I can't figure out how to build a proper search function in my Kinvey-based application. Right now I can just find values that match the text I type, and this is how:

KCSQuery* query = [KCSQuery queryOnField:@"key" withExactMatchForValue:textField.text];

[self.store queryWithQuery:query withCompletionBlock:^(NSArray *objectsOrNil, NSError *errorOrNil) {

    if (errorOrNil == nil) {

        [results removeAllObjects];
        [results addObjectsFromArray:objectsOrNil];

        [self.tableView reloadData];
    }

} withProgressBlock:nil];

Hopefully we can find a solution to this. Thanks in advance.


Solution

  • Do you mean to fetch results that contain “key” instead of the “exact match for key”?

    With KCSQuery(), you can achieve it using regular expressions like below:

    let query = KCSQuery(onField: “fieldname”” usingConditional: .KCSRegex, forValue: “Regular expression” )
    

    Also, refer http://devcenter.kinvey.com/ios/guides/datastore#Querying for better understanding of query creation using operators, modifiers etc.

    If this is not the case, can you please elaborate your use case along with an example?

    Thanks, Pranav Kinvey Support