has_many, polymorfic filter

0 views
Skip to first unread message

Sergey Avseyev

unread,
Sep 24, 2009, 7:37:01 AM9/24/09
to Thinking Sphinx
Hi all,

This is my schema:

class LinkItem < ActiveRecord::Base
belongs_to :item, :polymorphic => true
end

class Folder < ActiveRecord::Base
has_many :link_items, :as => :item
end

class Community < ActiveRecord::Base
has_many :link_items, :as => :item
end

class User < ActiveRecord::Base
has_many :link_items

define_index do
indexes :login

has links_items.community(:id), :as => :community_ids
end
end

I want perform earch like this:

User.search('foo', :with => { :community_ids => 3 })

But I get empty set. How I can check index (sphinx 0.9.8.1)?

Sergey Avseyev

unread,
Sep 24, 2009, 7:43:10 AM9/24/09
to Thinking Sphinx
TS doesn't create any joins for user_core index in generated config.

How can I get this behaviour?

Sergey Avseyev

unread,
Sep 24, 2009, 7:48:45 AM9/24/09
to Thinking Sphinx
>     has links_items.community(:id), :as => :community_ids
has link_items.community(:id), :as => :community_ids

Sorry for typo, but problem still exists

Sergey Avseyev

unread,
Sep 24, 2009, 7:59:48 AM9/24/09
to Thinking Sphinx
I try use has links_items.item(:id), but it also indexes folder. Can I
filter this association by type?

class User < ActiveRecord::Base
has_many :link_items

define_index do
indexes :login

has links_items.item(:id), :as => :community_ids
end
end

On Sep 24, 2:37 pm, Sergey Avseyev <sergey.avse...@gmail.com> wrote:

Greg DeVore

unread,
Sep 24, 2009, 9:42:20 AM9/24/09
to Thinking Sphinx
This is similar to a problem I was experiencing. What I ended up doing
was writing my own query and setting the index :source to :query. I
then had to hack thinking sphinx a little bit to account for delta
indexing. See this thread:
http://groups.google.com/group/thinking-sphinx/browse_thread/thread/0ebbeba3262f2d0f

Greg DeVore
Reply all
Reply to author
Forward
0 new messages