简体   繁体   English

在PHP和MYSQL中对搜索完整标题及其单词进行单一查询?

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM