Question

I have a mysql table that stores information about songs and their artists. On the client side, I have a web page that uses jQuery and Ajax to search through this data, in the form of an auto complete. For example, typing 'David B' would give back David Bowie. This works fine, but when someone wants to search for 'Mötley Crüe' they will have to type the special characters before it returns in the search results. I want users be able to type 'Motley C' and be auto completed to 'Mötley Crüe'.

Currently I build the select query and use a LIKE '%pattern%' to search for the artists. Is there any way to do this in MySQL?

Thank you!

Was it helpful?

Solution

This works out of the box if you store the artist's name with a unicode-aware and culture independent collation, such as utf8_general_ci. You can change the collation of a column with alter table:

alter table YourTable modify ArtistName varchar(255) collate utf8_general_ci;

If you can't/don't want to change the column collation you can use a specific collation in the query like this:

select * from YourTable where ArtistName like 'motley%' collate utf8_general_ci;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top