Order by an expression in Solr

后端 未结 3 647
半阙折子戏
半阙折子戏 2021-01-05 13:23

In SQL you can order by an expression like:

SELECT * FROM a
ORDER BY CASE WHEN a.Category = 20 THEN 1 ELSE 0 DESC

so records who have Categ

3条回答
  •  一向
    一向 (楼主)
    2021-01-05 13:48

    Solr doesn't have an if/then (at least not until 4.0), but it does have a map function and the ability to use function queries in your sort. You can probably use something like this in your sort to achieve what you're after:

     ?q=*&sort=map(category,20,20,case,0),score desc
    

    (untested)

    Here is a thread that talks about using map for an if statement.

提交回复
热议问题