Optimizing SQLite multiple LIKE search for iOS
I'm executing an SQLite select statement with several LIKE clauses in an iPhone application. The statements resemble the following:
SELECT * FROM mytable
WHERE name LIKE 'Smith %'
OR name LIKE '% Smith %'
OR name LIKE 'Smith_%'
OR name LIKE '% Smith_%';
The execution currently takes abo开发者_Go百科ut 0.5 seconds on my laptop and about 2 seconds on the device. I can't index the "name" column of "mytable" because of space constraints.
Each of the LIKE clauses is quite similar - if one fails, it's likely they each will. So I'd like to group these together some how to optimize my search.
Can this be done, say via REGEXP? If so, how and is REGEXP enabled by default?
Edit. I'm trying statements along the lines of:
SELECT * FROM mytable WHERE name REGEXP '[ _]?Smith[ _,]';
SQLite actually has a full text search engine built in. You may want to consider using it.
http://www.sqlite.org/fts3.html#section_1
精彩评论