I\'m porting my application searches over to Sphinx from MySQL and am having a hard time figuring this one out, or if it even needs to be ported at all (I really want to know if
No index can help you with this query, since you're looking for the string as an infix, not a prefix (you're looking for '%friendname%'
, not 'friendname%'
.
Moreover, the LIKE
solution will get you into corners: suppose you were looking for a friend called Ann. The LIKE
expression will also match Marianne, Danny etc. There's no "complete word" notion in a LIKE
expression.
A real solution is to use a text index. A FULLTEXT
index is only available on MyISAM
, and MySQL 5.6 (not GA at this time) will introduce FULLTEXT
on InnoDB
.
Otherwise you can indeed use Sphinx to search the text.
With just hundreds or thousands, you will probably not see a big difference, unless you're really going to do many searches per second. With larger numbers, you will eventually realize that a full table scan is inferior to Sphinx search.
I'm using Sphinx a lot, on dozens and sometimes hundreds of millions large texts, and can testify it works like a charm.
The problem with Sphinx is, of course, that it's an external tool. With Sphinx you have to tell it to read data from your database. You can do so (using crontab
for example) every 5 minutes, every hour, etc. So if rows are DELETE
d, they will only be removed from sphinx the next time it reads the data from table. If you can live with that - that's the simplest solution.
If you can't, there are real time indexes in sphinx, so you may directly instruct it to remove certain rows. I am unable to explain everything in this port, so here are a couple links for you:
Index updates
Real time indexes
As final conclusion, you have three options:
FULLTEXT
with InnoDB.At this point in time, I would certainly use option #3: use sphinx.