I am performing a sunspot (solr) search on a resource and filtering the results by my current users favorited resource. This works perfectly using the code below, however its requested that I sort the results and display when the user favorited that item (aka date created on the favorites model). I have no idea how to go about integrating that into my search while keeping the date specific to the user. Any ideas or solutions would be greatly appreciated.
class Resource < ActiveRecord::Base
has_many :favorites
has_many :favorite_users, through: :favorites
searchable do
text :title
...
integer :favorite_user_ids, references: User, multiple: true
end
def self.full_search(params={}, current_user)
search = Resource.search do
keywords params[:term]
with(:favorite_user_ids, current_user.id) if params[:filter] == 'favorite'
end
search
end
end