可以使用 current_user 对搜索结果进行排序
我正在尝试使用使用产品和用户输入的方程式对搜索结果进行排序。换句话说,我有一个使用来自 Products 和 current_user 的数据的方程。我希望能够按照从方程中得到的数字对搜索结果进行排序。我什至一开始就迷失了方向。有没有人做过类似的事情或者对如何最好地处理排序/顺序有任何想法?据我了解,“order”通常用于对 SQL 数据库中的实际列进行排序,而不是一种方法。
我最初认为我需要将 current_user 传递到模型中。我知道这不是最佳实践,但 Sunspot 允许您在模型中创建自定义字段,然后对这些字段进行排序。不幸的是,这不起作用,因为 sunspot 需要为其搜索和排序的字段建立索引。
我目前正在使用 Sunspot,并且即使需要进行修改也想继续使用它。我也在使用分页。
I'm trying to order search results using an equation that uses Products and User has inputs. In other words, I have an equation that uses data from both Products and current_user. I want to be able to order my search results by the number I get from the equation. I'm pretty lost on even were to begin with this. Has anyone done something similar or have any ideas of how to best handle the sort/order? From my understanding, "order" is usually used to sort actual columns in the SQL database and not a method.
I was originally thinking I would need to pass the current_user into the model. I know that's not best practice, but Sunspot allows you to create custom fields in the model and then sort on those fields. Unfortunately, this doesn't work since sunspot needs to index the fields it searches and sorts by.
I'm currently using Sunspot and would like to keep using it even if need to make modifications. I'm also using pagination.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您无法在 SQL 中计算复杂的方程。您只能进行简单的计算。
可能的解决方案:
使用 ruby 排序方法。
列或表
您的问题可能与“匹配”有关。
You cannot calculate complex equations in SQL. You are restricted to simple calculations.
Possible Solutions:
use the ruby sort method.
column or table
Your problem could be associated with "matching".