tags:

views:

22

answers:

2

I was recently watching a google lecture on mysql and learnt that MySQL wont use indexes for LIKE '%foo' searches.

My site's 'live search' (ajax search) searches the column full_details(TEXT), should i create a reversed version like full_details_rev(TEXT) and index that?

Or should i not index large text fields at all?

+1  A: 

Maybe an external fulltext indexing tool like Sphinx is more appropriate in this case.

Sjoerd
For high(er) volume of searches, Sphinx is a godsend. It might be a slight overkill here though...
Piskvor
+1  A: 

For fulltext searching (which is basically what you're doing), the fulltext index is much more efficient - for a brief intro, see e.g. this article; Google for more.

Example of use (assuming there is a fulltext index, otherwise you'll just get an error):

SELECT some_column FROM yourtable WHERE MATCH (full_details) AGAINST ('foo')

(a normal index on a reversed column would help you iff the original ends exactly with the search string (i.e. 'asdfsdafsdfaaaaafoo')

Piskvor
ah so the keyword would have to be on either end? bugger.
Haroldo
thanks for the article, looks good!
Haroldo
looks like you need to use the * wildcard instead of % for fulltext, search is that right?
Haroldo
@Haroldo: No. Fulltext search has its own syntax, added example.
Piskvor
cool, thanks for all your help
Haroldo