Make a single query to search for the full name and its words in PHP & MYSQL?

I want to search for products based on the entire name of the name as well as the name of the words. It is good to use LIKEto search for a product in mysql with UNION. My database is title(charchar(550)) = Colorzone Men Casual Wear Red Cotton Shirtnot Fulltext - What is the best search algorithm for PHP and MYSQL?

But I need below the search result ( First : Cotton Shirtrecord, Second Cotton record and Third : Shirtrecord. Do not display all records mixed) as a single request

MYSQL query: For Ex: title =Cotton Shirt

SELECT title FROM zapstore_ecom_products WHERE title LIKE '%Cotton Shirt%' //Get Whole Title products.
UNION
SELECT title FROM zapstore_ecom_products WHERE title LIKE '%Cotton%' //Get list for first word Title products.
UNION
SELECT title FROM zapstore_ecom_products WHERE title LIKE '%Shirt%' //Get list for last word Title products.

Suppose a user’s title has 4 or more words, then he will make 4 or more queries using UNION. Will we make this search one query?

+4
source share
1 answer

You can use the FULLTEXT search titlein logical mode against ('Cotton','Shirt')and ORDER BY score DESC this should give you the desired result

I have not tried mysql, but according to the theory explained in the MySQL Doc, it will work

+1
source

All Articles