Conditional sorting in Solr 3.6

亡梦爱人 提交于 2019-12-22 18:33:19

问题


We're running Solr 3.6 and are trying to apply a conditional sort on the result set. To clarify, the data is a set of bids, and we want to add the option to sort by the current user's bid, so it can't function as a regular sort (as the bid will be different for each user that runs the query).

The documents in the result set include a "CurrentUserId" and "CurrentBid" field, so I think we need something like the following to sort:

sort=((CurrentUserId = 12345) ? CurrentBid : 0) desc

This is just pseudocode, but the idea is that if the currentUserId in Solr matches the user Id (12345 in this example), then sort by CurrentBid, otherwise, just use 0.

It seems like doing a sort by query might be the way to go with achieving this (or at least form part of the solution), using something like the following query:

http://localhost:8080/solr/select/?q=:&sort=query(CurrentUserId:10330 AND CurrentBid:[1 TO *])+desc

This doesn't seem to be working for me though, and results in the following error:

sort param could not be parsed as a query, and is not a field that exists in the index: ...

The Solr documentation indicates that the query function can be used as a sort parameter from Solr 1.4 onwards, so this seems like it should work.

Any advice on how to go about achieving this would be greatly appreciated.


回答1:


According to the Solr Documentation link you provided,

Any type of subquery is supported through either parameter dereferencing $otherparam or direct specification of the query string in the LocalParams via "v".

So based on the examples and your query, I think one or both of the following should work:

http://localhost:8080/solr/select/?q=:&sort=query($qq)+desc&qq=(CurrentUserId:10330 AND CurrentBid:[1 TO *])

http://localhost:8080/solr/select/?q=:&sort=query({v='CurrentUserId:10330 AND CurrentBid:[1 TO *]'})+desc



来源:https://stackoverflow.com/questions/12749669/conditional-sorting-in-solr-3-6

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!