[英]Make single query for search full title and its words in PHP & MYSQL?
I want to make a search for products based on whole title name and also title words. 我想根据整个标题名称和标题词来搜索产品。 It's ok to use
LIKE
for searching product in mysql by using UNION
. 这是确定使用
LIKE
通过使用MySQL的搜索产品UNION
。 My database title(charchar(550)) = Colorzone Men's Casual Wear Red Cotton Shirt
not a Fulltext -- 我的数据库
title(charchar(550)) = Colorzone Men's Casual Wear Red Cotton Shirt
不是全文 - What is the best search Algorithm for PHP & MYSQL? 什么是PHP和MYSQL的最佳搜索算法?
But I need to below the search result( First : Cotton Shirt
record, Second Cotton
record and Third : Shirt
record. Should not showing all the records mixed) as single query 但我需要低于搜索结果( 第一 :
Cotton Shirt
记录, 第二 Cotton
记录和第三 : Shirt
记录。不应显示所有记录混合)作为单一查询
MYSQL Query: For Ex: Title = Cotton Shirt
MYSQL查询:对于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 the user title have 4 or more words then it will make 4 or more query by using UNION
. 假设用户标题有4个或更多单词,那么它将使用
UNION
进行4个或更多查询。 We will make this search with single query? 我们将使用单个查询进行此搜索?
You can use FULLTEXT search on title
in boolean mode against ('Cotton','Shirt')
and ORDER BY score DESC
This should give you your desired output 您可以在布尔模式下
against ('Cotton','Shirt')
title
使用FULLTEXT搜索against ('Cotton','Shirt')
和ORDER BY score DESC
这应该可以为您提供所需的输出
I didn't try mysql but according to theory explained in MySQL Doc it will work 我没有尝试过mysql但是根据MySQL Doc中解释的理论它会起作用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.