title: Use NSPredicate to search multiple fields
body: <p>I have a UITableView, and want to be able to search multiple property fields (in each <strong>RMLObject</strong> entry in an <strong>RMLResults</strong> array) using <strong>NSPredicate</strong>.  I'm attempting to do this by using '<em>OR</em>' in the predicateFormatString:</p>
  
  <pre><code>NSString *predicateFormat = @"(transactionDescription CONTAINS [c] %@) OR (transactionNote CONTAINS [c] %@)";
  
  NSPredicate *predicate = [NSPredicate predicateWithFormat:predicateFormat, searchText, searchText];
  </code></pre>
  
  <p><strong>searchText</strong> is an NSString, and <strong>transactionDescription</strong> and <strong>TransactionNote</strong> are NSString properties in an RLMObject.</p>
  
  <p>I'm passing predicate to the following REALM API call:</p>
  
  <pre><code>- (RLMResults *)objectsWithPredicate:(NSPredicate *)predicate;
  </code></pre>
  
  <p>However, this isn't finding the all the fields or records where searchText is part of the property.</p>
  
  <p>If I limit it to just a single field(<strong>transactionDescription</strong>), it does find all instances:</p>
  
  <pre><code>predicateFormat = @"transactionDescription CONTAINS [c] %@";
  </code></pre>
  
  <p>Edited:  The following is what I now have (and still does not find all the objects that contain matches):</p>
  
  <pre><code>RLMResults *dataToSearch =  &lt; code to fill dataToSearch here ... &gt;;
  
  // show dataToSearch
  
  NSLog(@"dataToSearch:  %@", [dataToSearch description]);
  
  // build predicate
  
  NSString *predicateFormat = @"(transactionDescription CONTAINS [c] %@) OR (transactionNote CONTAINS [c] %@)";
  NSPredicate *predicate = [NSPredicate predicateWithFormat:predicateFormat, searchText, searchText];
  
  // search
  
  _searchResults  = [dataToSearch objectsWithPredicate:predicate];
  
  // show results
  
  NSLog(@"searchResults:  %@",[_searchResults description]);
  </code></pre>
  
  <p>The actual data has 5 instances where one or the other of the fields have a "g" in the string.  They are:</p>
  
  <ul>
  <li>transactionDescription:  4</li>
  <li>transactionNote:  1</li>
  </ul>
  
  <p>I tried 3 different NSPredicate formats:</p>
  
  <pre><code>// A:
  
  NSString *predicateFormat = @"(transactionDescription CONTAINS [c] %@) OR (transactionNote CONTAINS [c] %@)";
  NSPredicate *predicate = [NSPredicate predicateWithFormat:predicateFormat, searchText, searchText];
  
  // B:
  
  NSString *predicateFormat = @"(transactionDescription CONTAINS [c] %@)";
  NSPredicate *predicate = [NSPredicate predicateWithFormat:predicateFormat, searchText];
  
  // C:
  
  NSString *predicateFormat = @"(transactionNote CONTAINS [c] %@)";
  NSPredicate *predicate = [NSPredicate predicateWithFormat:predicateFormat, searchText];
  </code></pre>
  
  <p>(compound) Predicate A found:</p>
  
  <ul>
  <li>1 instance in transactionDescription</li>
  <li>1 instance in transactionNote</li>
  </ul>
  
  <p>Predicate B found:</p>
  
  <ul>
  <li>4 (all) instances in transactionDescription</li>
  <li>0 instances in transactionNote</li>
  </ul>
  
  <p>Predicate C found:</p>
  
  <ul>
  <li>0 instances in transactionDescription</li>
  <li>1 (the only) instance in transactionNote</li>
  </ul>
  
  <p>Predicate formats B &amp; C seem to be functioning as expected - they just search a single field, and find all instances where the string has the character 'g' in it.</p>
  
  <p>While predicate A (the compound predicate) does appear to be looking at both fields, it appears to be stopping the search after finding 2 hits (missing the other 3).</p>
  
  <p>I tried the ANY aggregate operator in several configurations, but all of the following NSPredicates (and several other variations) resulted in an exception when calling objectsWithPredicate:</p>
  
  <pre><code>@"ANY (transactionDescription CONTAINS [c] %@) OR ANY transactionNote CONTAINS [c] %@)";
  
  @"(ANY transactionDescription CONTAINS [c] %@) OR (ANY transactionNote CONTAINS [c] %@)";
  
  @"ANY (transactionDescription CONTAINS [c] %@ OR transactionNote CONTAINS [c] %@)";
  </code></pre>
  
  <p>Any clues on why (compound) Predicate A bails after finding just 2 hits?</p>