2

So I am working on this schema.

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

Indices

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

I am trying to use ThinkSphinx to do a search on segment and use condition that belongs to person. An example would be search all the Segments that have people that are female. However if I do a ThinkSphinx.search "",:with=>{:segment_ids=>1},:conditions=>{:gender=>"Female"} I will get 0 results.

pat
  • 16,116
  • 5
  • 40
  • 46
fenec
  • 5,637
  • 10
  • 56
  • 82
  • 1
    You're referring to an attribute `segment_ids` in your search example, but it's not in either index. Should it be? – pat Apr 07 '14 at 22:52
  • Is there a documentation i can follow about indexing, many-to-many relationships with thinking sphinx? – fenec Apr 08 '14 at 14:59
  • 2
    There's no super detailed documentation on many-to-many relationships specifically, no. All association data can be indexed by following the association names for a field or attribute definition, though, as mentioned in the general indexing documentation: http://pat.github.io/thinking-sphinx/indexing.html – pat Apr 09 '14 at 10:29

0 Answers0