开发者

Possible to order search results using current_user

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 tho开发者_JS百科se 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.


You cannot calculate complex equations in SQL. You are restricted to simple calculations.

Possible Solutions:

  • Depending on how many results you get it might be possible to just use the ruby sort method.
  • Calculate the result of your equation and store them in a new column or table

Your problem could be associated with "matching".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜