使用整个模型编号时,MYSQL搜索返回不正确的结果

时间:2016-04-14 18:34:14

标签: mysql

我有以下mysql查询,其中包含型号为HA / 200

的产品的样本数据

搜索型号时,不会返回该特定产品的结果,但会包含其他产品。

如果我搜索HA /然后列出了HA / 200产品,实际上是最重的加权搜索结果。

我很难理解为什么HA /将返回HA / 200,但HA / 200不会。 这让我最困惑。来自以下sql查询的任何建议??

SELECT DISTINCT
    p.products_model,
    p.products_image,
    p.products_quantity,
    m.manufacturers_id,
    p.products_id,
    pd.products_name,
    p.products_price,
    p.products_tax_class_id,
    p.products_price_sorter,
    p.products_qty_box_status,
    p.master_categories_id,
    IF (
        p.products_model LIKE "HA/200",
        1050, 
        IF( 
            p.products_model LIKE "%HA/200%",
            700,
            0
        ) + IF (
            MATCH(pd.products_name, pd.products_description) AGAINST("HA/200 HA/200s"),
            MATCH(pd.products_name, pd.products_description) AGAINST("HA/200 HA/200s") * 10,
            0
        )
    ) + IF (
        MATCH(m.manufacturers_name) AGAINST("HA/200 HA/200s"),
        MATCH(m.manufacturers_name) AGAINST("HA/200 HA/200s") * 5,
        0
    ) + IF (
        MATCH(p.products_model) AGAINST("HA/200 HA/200s"),
        MATCH(p.products_model) AGAINST("HA/200 HA/200s") * 700,
        0
    ) + (pd.products_viewed / 8206.421) as weight 
FROM (
    products p LEFT JOIN manufacturers m USING(manufacturers_id),
    products_description pd,
    categories c,
    products_to_categories p2c
)
LEFT JOIN meta_tags_products_description mtpd
    ON mtpd.products_id= p2c.products_id AND mtpd.language_id = 1 
WHERE (
    p.products_status = 1 
    AND p.products_id = pd.products_id
    AND pd.language_id = 1 
    AND p.products_id = p2c.products_id 
    AND p2c.categories_id = c.categories_id  
    AND (
        MATCH(p.products_model, pd.products_description) AGAINST("HA/200* HA/200s*" IN BOOLEAN MODE)
        OR MATCH(p.products_model) AGAINST("HA/200* HA/200s*" IN BOOLEAN MODE)
        OR MATCH(m.manufacturers_name) AGAINST("HA/200* HA/200s*" IN BOOLEAN MODE)
        OR MATCH(mtpd.metatags_keywords, mtpd.metatags_description) AGAINST("HA/200* HA/200s*" IN BOOLEAN MODE)
    )
)
ORDER BY weight DESC

0 个答案:

没有答案