Skip to content

Searching For Phrases

cmancushman edited this page Oct 27, 2017 · 4 revisions

The Purpose of Searching for Phrases

Search conditions are used to find rows where one or more fields match a given phrase. For example, by using a search we could find rows in which a column named 'Memo' matches the phrase 'gate five,' or in other words 'Memo' contains a phrase that is close enough to 'gate five.' We could also find rows in which a column called 'Model' matches the phrase 'truck' but excludes the word 'red,' if we wanted to retrieve truck models that don't include red trucks.


Condition That Checks if Given Columns Contain Matches to a Phrase (NSString)

Declaration

+(instancetype) columnsWithNames:(NSArray<NSString *> *)columnNames matchPhrase:(NSString *)phrase;

Example

//get the first 3 rows where column 'Name' contains matches for the phrase 'Matt.' Example matches include 'James,' 'James Ferguson,' and 'Matt James.'
[weakSelf.table getFirst:3 
rowsWhere:[StackBaseCondition columnsWithNames:[@"Name"] matchPhrase:@"James"]  
completionBlock:^(BOOL success, NSString *responseMessage, NSArray<NSDictionary *> *responseTable) {
    
    for(NSDictionary *row in responseTable){
        
        NSLog(@"row %ld: %@", ([responseTable indexOfObject:row] + 1), row);
        
    }
    
}];

Condition That Checks if Given Columns Contain Matches to a Phrase (NSString) While Also Excluding Results That Contain Key Phrases (NSStrings)

Declaration

+(instancetype) columnsWithNames:(NSArray<NSString *> *)columnNames matchPhrase:(NSString *)phrase butDoNotContainPhrases:(NSArray<NSString *> *)excludedPhrases;

Example

//get the first 3 rows where column 'Model' contains matches for the phrase 'truck' but does not include the words 'red' or 'green.' Example matches include 'Ford truck,' and 'Blue Toyota Truck,' but do not include 'green Ford truck' or 'red Honda truck.'
[weakSelf.table getFirst:3 
rowsWhere:[StackBaseCondition columnsWithNames:[@"Model"] matchPhrase:@"truck" butDoNotContainPhrases:@["red", "green"]]  
completionBlock:^(BOOL success, NSString *responseMessage, NSArray<NSDictionary *> *responseTable) {
    
    for(NSDictionary *row in responseTable){
        
        NSLog(@"row %ld: %@", ([responseTable indexOfObject:row] + 1), row);
        
    }
    
}];

Note on Searching for Phrases

  • When passing numeric values into rows (@"example_numeric_field" : @4) or conditions ([StackBaseCondition columnWithName:@"id" isEqualTo:@1]), the numbers must be formatted as NSNumbers or be prefixed with '@' in order to be processed by the backend.
  • When using columnsWithNames: matchPhrase: butDoNotContainPhrases: if you have a very small number of rows you may not see results exclude the desired phrases. This is because the algorithm behind it favors returning at least a few results over following the rule perfectly. However, it will always return the rows that fit the algorithm best first.

Clone this wiki locally