所以我正在研究这个架构。
segment.rb
class Segment < ActiveRecord::Base
attr_accessible :broadcast_date, :comment, :name, :person_id, :episode_id, :segment, :tv_show_id, :person_ids,:balance
...
has_many :personSegments
has_many :people , :through => :personSegments
end
person.rb
class Person < ActiveRecord::Base
attr_accessible :alignment, :gender, :source, :ethnicity, :description, :first_name, :last_name , :profession_ids, :roles_attributes
# avoid duplicate
validate :first_name, :presence => true, :uniqueness => {:scope => :last_name}, :message => "that name existe already"
#segments
has_many :personSegments
has_many :segments , :through => :personSegments
end
person_segment.rb
class PersonSegment < ActiveRecord::Base
attr_accessible :person_id, :segment_id
belongs_to :person
belongs_to :segment
validates_uniqueness_of :person_id, :scope => [:segment_id]
end
指数
segment_index.rb
ThinkingSphinx::Index.define :segment, :with => :active_record, :delta => true do
# fields
indexes name, :sortable => true
# attributes
has created_at, updated_at
has broadcast_date, :as => :segment_broadcast_date
has person_id
has tv_show(:id), :as => :tv_show_ids
has '7', :as => :model_order, :type => :integer
end
person_index.rb
ThinkingSphinx::Index.define :person, :with => :active_record, :delta => true do
#Fields
indexes last_name, :sortable => true
indexes first_name, :sortable => true
indexes alignment
indexes gender
indexes ethnicity
#indexes role(:active), :as => :active
#indexes role.active, :as => :active_ids
#Attributes
has created_at, updated_at
has professions(:id), :as => :profession_ids
has positions(:id), :as => :position_ids
has organizations(:id), :as => :organization_ids
has tvShows(:id), :as => :tv_show_ids
#has roles.active, :as => :active, :type => :integer
# has roles.active, :as => :active_ids
has '6', :as => :model_order, :type => :integer
end
我正在尝试使用ThinkSphinx对段进行搜索并使用属于人的条件。一个例子是搜索所有具有女性人的细分。 但是,如果我做一个ThinkSphinx.search&#34;&#34;,:with =&gt; {:segment_ids =&gt; 1},:conditions =&gt; {:gender =&gt;&#34; Female&#34;我将得到0结果。