我正在研究搜索算法,尝试按相关性对它们进行排名时遇到了麻烦。谁能轻轻地提供一些帮助? $这是查询:
SELECT `listings`.*,
`c`.`category_name`,
`p`.`profile_name`,
CASE WHEN Lower(listings.title) IN ("pizzeria", "ristorante") THEN 1 ELSE
0 end
+ CASE WHEN Lower(listings.address) IN ("pizzeria", "ristorante") THEN 1
ELSE 0
end + CASE WHEN Lower(c.category_name) IN ("pizzeria", "ristorante") THEN
1 ELSE
0 end + CASE WHEN Lower(co.province) IN ("pizzeria", "ristorante") THEN 1
ELSE 0
end AS rank,
`co`.`comune` AS `comune`,
`co`.`province` AS `province`,
`co`.`region` AS `region`,
`co`.`short_code`,
`u`.`username`
FROM `listings`
LEFT JOIN `comune` `co`
ON `listings`.`id_city` = `co`.`id`
LEFT JOIN `aauth_users` `u`
ON `listings`.`id_user` = `u`.`id`
LEFT JOIN `categories` `c`
ON `listings`.`id_category` = `c`.`id`
LEFT JOIN `profiles` `p`
ON `listings`.`id_profile` = `p`.`id`
WHERE ( `listings`.`title` LIKE '%pizzeria%' escape '!'
OR `c`.`category_name` LIKE '%pizzeria%' escape '!'
OR `listings`.`address` LIKE '%pizzeria%' escape '!'
OR `co`.`province` LIKE '%pizzeria%' escape '!' )
OR ( `listings`.`title` LIKE '%ristorante%' escape '!'
OR `c`.`category_name` LIKE '%ristorante%' escape '!'
OR `listings`.`address` LIKE '%ristorante%' escape '!'
OR `co`.`province` LIKE '%ristorante%' escape '!' )
ORDER BY `rank` ASC
LIMIT 15
listings.title中的文本比萨店和类别名称中的ristorante应该输出[rank] => 2,但是当我打印结果数组时,它显示[rank] => 0。