【问题标题】:Make single query for search full title and its words in PHP & MYSQL?在 PHP 和 MYSQL 中对搜索完整标题及其单词进行单一查询?
【发布时间】:2016-10-07 11:14:50
【问题描述】:

我想根据整个标题名称和标题词搜索产品。可以使用LIKE 在mysql 中使用UNION 搜索产品。我的数据库title(charchar(550)) = Colorzone Men's Casual Wear Red Cotton Shirt 不是Fulltext -- What is the best search Algorithm for PHP & MYSQL?

但我需要在搜索结果下方(第一Cotton Shirt记录,第二Cotton记录和第三:@987654329 @记录。不应该将所有记录混合显示)作为单个查询

MYSQL 查询: 例如: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.

假设用户标题有4个或更多单词,那么它将使用UNION进行4个或更多查询。我们将使用单个查询进行此搜索?

【问题讨论】:

    标签: php mysql search sql-like


    【解决方案1】:

    您可以在布尔模式 against ('Cotton','Shirt')ORDER BY score DESC 上对 title 使用 FULLTEXT 搜索 这应该会给你你想要的输出

    我没有尝试 mysql,但根据 MySQL Doc 中解释的理论,它会起作用

    【讨论】:

    • 好的。谢谢你的回答。
    • 最好包含一些代码示例来改进这个答案
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-30
    相关资源
    最近更新 更多