我们正在运行 Solr 3.6 并尝试对结果集应用条件排序。澄清一下,数据是一组出价,我们希望添加按当前用户的出价排序的选项,因此它不能用作常规排序(因为运行查询的每个用户的出价都会不同) )。
结果集中的文档包含“CurrentUserId”和“CurrentBid”字段,因此我认为我们需要如下所示的内容进行排序:
sort=((CurrentUserId = 12345) ? CurrentBid : 0) desc
这只是伪代码,但其思想是,如果 Solr 中的 currentUserId 与用户 Id 匹配(本例中为 12345),则按 CurrentBid 排序,否则仅使用 0。
似乎通过查询进行排序可能是实现此目的的方法(或至少构成解决方案的一部分),使用类似以下查询的内容:
http://localhost:8080/solr/select/?q=<em>:</em>&sort=query(CurrentUserId:10330 AND CurrentBid:[1 TO *])+desc
但这似乎对我不起作用,并导致以下错误:
sort param could not be parsed as a query, and is not a field that exists in the index: ...
Solr documentation表示从 Solr 1.4 开始,查询函数可以用作排序参数,所以这看起来应该可行。
任何有关如何实现这一目标的建议将不胜感激。
最佳答案
根据您提供的 Solr 文档链接,
Any type of subquery is supported through either parameter dereferencing $otherparam or direct specification of the query string in the LocalParams via "v".
因此,根据示例和您的查询,我认为以下一项或两项应该有效:
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
关于sorting - Solr 3.6 中的条件排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12749669/