Sunspot Solr specialized search

Hello all,

I have a question that I’ve searched for a bit but can’t really find
anything. I might not be searching on the right things.

I have Sunspot/solr working great and now I want to start using it to
speed up Backbone.js queries. I have it currently working with straight
Rails.

==================
CONTROLLER
def members
@group = Group.find(params[:group_id])
@members = @group.members.nil? ? nil : @group.members.reject {
|user| !user.active? }
respond_with(@members.to_json
end

MODEL (Group)
def members
@members ||= roles.members.collect { |role| role.user }.compact
unless roles.members.empty?
end

Basically I’m trying to figure out a way to return :members method’s
results more quickly. I know with sunspot/solr you can index methods,
but this helps with searching on a member get getting the group. I
basically need the opposite.

What makes this more complicated is that Group has_many :users, :through
=> :roles as a polymorphic relationship.

Roles table

user_id => user’s id
object_type => object for (Group, Forum, etc)
object_id => id of object (Group, Forum, etc)

I know its complicated but it really needs to be this way. If anyone
has any ideas I would greatly appreciate it.

Thanks

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs