Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Text Search across multiple fields MySQL

Tags:

mysql

I have a MySQL table laid out like this:

ID | Artist | Title

Which contains song information obtained from MP3 ID3 tags.

Now, I would like to be able to run a search on this, however the incoming data could be in a variety of formats. I'm sure you all know how ID3 tags can end up after a couple of people have had hold of them.

I have the following query which I have tried, but looking at it now, I understand completely why it doesnt bring back a result set. I'm fresh out of ideas.

SELECT CONCAT(artist, ' ',title) as trackname 
FROM sound_tracklist 
WHERE CONCAT(artist,' ',title) LIKE '%[JunkTags]Artist - Title[More Junk - www.junkwebsite.com]%'

I'd appreciate any input/direction on this.

Thanks

like image 597
Dave Avatar asked Mar 25 '26 00:03

Dave


1 Answers

If you're in MyISAM type tables, try using a FULLTEXT index:

ALTER TABLE sound_tracklist ADD FULLTEXT INDEX (artist, title);

then you can do

SELECT artist, title FROM sound_tracklist WHERE MATCH (artist, title) AGAINST ('bach brandenburg concerto')

it wouldn't catch misspellings ("konshertoe", anyone?), but it would search for your specified keyboards across all the fields in the index, and catch them in any order.

like image 187
Marc B Avatar answered Mar 26 '26 16:03

Marc B



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!