我正在创建一个简单的逻辑来根据相关性订购产品。如果指定的关键字出现在标题,说明或标签上,我会给它一个等级。如果关键字出现在标题上,它将具有更高的优先级。
按等级标题,等级描述,等级标签排序
我在这里使用一些静态值作为用户输入。 “相关性”将是类似param_orderby
的参数select *, case when title like '%eletronic%' then 1 else 0 end as rank_title,
case when description like '%eletronic%' then 1 else 0 end as rank_description,
case when tags like '%eletronic%' then 1 else 0 end as rank_tag from products where title like '%eletronic%' or description like '%eletronic%' or tags like '%eletronic%'
order by
(case when 'relevance' = 'price_ascending'
then price end ) desc,
(case when 'relevance' = 'price_descending' then price end) asc,
(case when 'relevance' = 'relevance' then
//I cannot use multple columns here
rank_title, rank_description, rank_tag end
)