Let say I have a MySQL server with one table that has over 1 million records. For the sake of illustration let say those are products. To make it simple the table has only 3 columns:
product_id - name - price
Let say I have one table displaying the information. Through a TextBox, with each key press, I wan't to select the products that contains the string in that TextBox, additionally the TextBox can have multiple search strings (up to 3) divided by a character '^' so if the TextBox had a string like: "st ^ b ^ ry" it would select products that contains 'st', 'b' and 'ry'.
I made the query like this:
SELECT
product_id,
name,
price
FROM
products
WHERE
name LIKE %{Param1}%
AND name LIKE %{Param2}%
AND name LIKE %{Param3}%
ORDER BY
name ASC
Locally this is fine I guess but when the program is being used somewhere else the query and table takes forever to load after each key press. So...
- What is the best way to do this?
- Is there a better way to get what i want instead of 3 "LIKE" or is it right how I did it?
UPDATE
I've checked the questions posted by Loathing and according to what I read the best solution is:
SELECT name FROM table
WHERE MATCH (name) AGAINST ('keyterm');
Having a FULLTEXT index (with MyISAM engine). But the problem with that is that it won't show partial entries. If I had a product called "1/2 Blue Strawberry" and in keyterm I have 'a' (as an example), nothing will show up. I don't want it to just look for words but every record containing whatever I want even if that is a single letter.