Full Text Search (Part 6)

Heretofore, I’ve been working with an “OR” implementation of Full-Text Search (FTS). This sort of implementation takes one or more keywords, and returns all the objects which match one or more of them. I’d been avoiding an “AND” implementation (which only returns objects which contain all the specified keywords) because I suspected that the Core Data/SQLite combination would make a hash of the necessary query plans, but this turns out not to be the case. So today: “AND” style FTS!

NSPredicate

The only difference between “AND” and “OR” FTS is the predicate we use to filter the results. Here’s the NSPredicate construction code we’ve been using for the “OR” implementation:

This runs in about 0.13s on my iPhone 3G; that’s not great, but not horrible either. Considering that I didn’t expect the query to stay on the indices at all, I’m pretty happy. Which proves once again, I suppose, that low expectations are the key to happiness.