我有一个查询从我的数据库中选择,然后按相关性排序:
select * from `table` where MATCH (`name`) AGAINST (:search IN BOOLEAN MODE) order by MATCH (`name`) AGAINST (:search2 IN BOOLEAN MODE) desc LIMIT :start, :limit
当显示这些结果时,我希望用户可以选择按价格过滤。当ORDER BY已用于相关性时,我该怎么做?
我可以创建结果视图,然后查询视图以按价格过滤吗?
答案 0 :(得分:0)
您可以根据需要订购任意数量的列。语法是:
ORDER by column1 desc, column2 asc, column3 desc ...
所以你可能希望:
select * from `table` where MATCH (`name`) AGAINST (:search IN BOOLEAN MODE) order by MATCH (`name`) AGAINST (:search2 IN BOOLEAN MODE) desc, `price` asc LIMIT :start, :limit
如果您想要价格范围,则必须将其构建为WHERE子句
select * from `table` where MATCH (`name`) AGAINST (:search IN BOOLEAN MODE) AND `price` >= 5 AND `price` < 10 order by MATCH (`name`) AGAINST (:search2 IN BOOLEAN MODE) desc, `price` asc LIMIT :start, :limit