We are using sqlite on an iPhone app. In a search box, we want to query the database and return any values that are associated with what the user is typing in. Currently, we are searching on a few different columns like
Gene
Disease
Medicine
Keywords
We started with the brute force method of calling this method (with some pseudo-code) when the search text changes:
// Basically we do this for our 4 columns we are searching on
NSString *query2 = [NSString stringWithFormat:@"select * from MedicineList where MedicineList.Keywords like \"%%%@%%\"",searchtext];
FMResultSet * rs2 = [ _patientAnnotatedDatabase executeQuery:query2];
while ([rs2 next])
{
// if you find anything, put it in a dictionary
}
[rs2 close];
It’s one big method that searches on the columns and returns a dictionary of results. It works when our dataset was small. Now of course that our dataset is bigger, it’s not that performant. Besides creating indices on the columns we are searching on, are there other performance things we can do? Thanks in advance.
LIKEpatterns like%word%cannot be optimized with normal indexes.Searching for words is what SQLite’s full text search extension is designed for.