在 PHP 和 MYSQL 中进行单个查询以搜索完整标题及其单词?
Make single query for search full title and its words in PHP & MYSQL?
我想根据整个标题名称和标题词搜索产品。使用UNION
可以在mysql中使用LIKE
搜索产品。我的数据库 title(charchar(550)) = Colorzone Men's Casual Wear Red Cotton Shirt
不是 Fulltext --
但是我需要在搜索结果下方(第一:Cotton Shirt
记录,第二Cotton
记录和 第三个:Shirt
记录。不应将所有记录混合显示)作为单个查询
MYSQL 查询: 例如:标题 = 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.
假设用户标题有4个或更多的词,那么它将使用UNION
进行4个或更多的查询。我们将使用单个查询进行搜索?
您可以在布尔模式 against ('Cotton','Shirt')
和 ORDER BY score DESC
中对 title
使用全文搜索
这应该会给你你想要的输出
我没有尝试 mysql 但根据 MySQL 文档中解释的理论,它会起作用
我想根据整个标题名称和标题词搜索产品。使用UNION
可以在mysql中使用LIKE
搜索产品。我的数据库 title(charchar(550)) = Colorzone Men's Casual Wear Red Cotton Shirt
不是 Fulltext --
但是我需要在搜索结果下方(第一:Cotton Shirt
记录,第二Cotton
记录和 第三个:Shirt
记录。不应将所有记录混合显示)作为单个查询
MYSQL 查询: 例如:标题 = 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.
假设用户标题有4个或更多的词,那么它将使用UNION
进行4个或更多的查询。我们将使用单个查询进行搜索?
您可以在布尔模式 against ('Cotton','Shirt')
和 ORDER BY score DESC
中对 title
使用全文搜索
这应该会给你你想要的输出
我没有尝试 mysql 但根据 MySQL 文档中解释的理论,它会起作用