Search Results
Searches return a ResourceCollection which implements Iterable, so you can iterate over them like other iterable classes.
TransactionSearchRequest request = new TransactionSearchRequest().
status().is(Transaction.Status.AUTHORIZED);
ResourceCollection<Transaction> collection = gateway.transaction().search(request);
for (Transaction transaction : collection) {
System.out.println(transaction.getId());
}
Race Conditions
To optimize the processing of large searches, data is retrieved from the server in chunks. Initially the server returns a list of ids that matched the search criteria, and then the clients request the full records in chunks. While you’re iterating over search results, two race conditions exist.
Records are Deleted
It’s possible for a record to be deleted between the time that the server returned the list of ids that matched the search criteria and when the client requested full details for that id. In this case, that record is skipped.
Records are Updated
It’s possible for a record to be updated between the time that the server returned the list of ids that matched the search criteria and when the client requested full details. In this case, if the record still matches the search criteria, it will be returned. If it no longer matches the search criteria, it will not be returned.
Maximum Size
Because of the race conditions described above, you cannot know specifically how many search results you will get when you’re iterating over them. However, you do know the maximum number of results that will be given.
TransactionSearchRequest request = new TransactionSearchRequest().
status().is(Transaction.Status.AUTHORIZED);
ResourceCollection<Transaction> collection = gateway.transaction().search(request);
collection.getMaximumSize();
// e.g. 33
Search Limit
We currently cap searches to 10,000 maximum results.