使用关键字$ search搜索记录集的最佳方法可能是首先显示,然后将剩余记录拉入查询并随机排序。换句话说,将搜索结果放在顶部,然后随机保留记录。这是我搜索的第一部分:
SELECT first_name, last_name, title, agency, address,
phone, more_info, description, img_name, active
FROM realtor
WHERE MATCH as rank (first_name, last_name, agency, description)
AGAINST ('$search' IN BOOLEAN MODE)
ORDER BY rank DESC
然后我想使用ORDER BY RAND()将剩下的记录设置为UNION 或者有更好的方法来执行此查询?这是我第一次尝试UNION。
此外,我的排名似乎不起作用,因为我搜索fname lname我没有得到fname lname记录,因为许多记录在title列中都有lname。有一个更好的方法吗?致谢
答案 0 :(得分:0)
请试试这个
SELECT first_name, last_name, title, agency, address,
phone, more_info, description, img_name, active,
MATCH (first_name, last_name, agency, description) AGAINST ('$search' IN BOOLEAN MODE) as relv
FROM realtor
HAVING relv>0 order by relv DESC