Forum: Ruby on Rails Sunspot Solr specialized search

Posted by Keith Raymond (sparkmasterflex)
on 2012-11-21 15:34
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
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.