我正在尝试按相关性对数据库进行搜索。

以下两个查询均有效,只有第一个查询不返回结果。

我曾尝试使用IN BOOLEAN MODE,但这只是使我的title_relevance和desc_relevance字段为0或1,因此我想根据一个术语的相关性进行适当排名,而不仅仅是它是否出现。

有什么办法可以做到这一点?

谢谢!

第一个查询:

SELECT
    rcv_id,
    rcv_title,
    rcv_desc,
    (MATCH(rcv_title) AGAINST ('nur*')) AS title_relevance,
    (MATCH(rcv_desc) AGAINST ('nur*')) AS desc_relevance
FROM rc_vacancy
WHERE
    ( MATCH(rcv_title,rcv_desc) AGAINST ('nur*') )
    AND rcv_deleted = 'off'
    AND rcv_active = 'on'
    AND rcv_type = 'P'
ORDER BY title_relevance DESC, desc_relevance DESC, rcv_lastupdated


第二查询:

SELECT
    rcv_id,
    rcv_title,
    rcv_desc,
    (MATCH(rcv_title) AGAINST ('nurse')) AS title_relevance,
    (MATCH(rcv_desc) AGAINST ('nurse')) AS desc_relevance
FROM rc_vacancy
WHERE
    ( MATCH(rcv_title,rcv_desc) AGAINST ('nurse') )
    AND rcv_deleted = 'off'
    AND rcv_active = 'on'
    AND rcv_type = 'P'
ORDER BY title_relevance DESC, desc_relevance DESC, rcv_lastupdated


在不使用通配符的情况下搜索“ nur”也会产生零结果:

SELECT
    rcv_id,
    rcv_title,
    rcv_desc,
    (MATCH(rcv_title) AGAINST ('nur')) AS title_relevance,
    (MATCH(rcv_desc) AGAINST ('nur')) AS desc_relevance
FROM rc_vacancy
WHERE
    ( MATCH(rcv_title,rcv_desc) AGAINST ('nur') )
    AND rcv_deleted = 'off'
    AND rcv_active = 'on'
    AND rcv_type = 'P'
ORDER BY title_relevance DESC, desc_relevance DESC, rcv_lastupdated

最佳答案

可能是AGAINST中的表达式不应包含通配符吗?您正在执行全文搜索,而不是类似LIKE的查询。

关于php - 在MySQL中按相关性匹配单词和顺序的一部分,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14524105/

10-09 04:33