Note that there are some explanatory texts on larger screens.

plurals
  1. PORails associations and Thinking Sphinx Indexing to refactor search method in controller
    primarykey
    data
    text
    <p>I'm working with a old database and drawing blank on how to set up the association and index it with Thinking Sphinx. I want to index the People and Group's skill.</p> <p>I have Users. Users can create People and Groups. People and Groups have a single skill through Sharing_Skill.</p> <p>people and groups tables: ID field, Name field</p> <p>sharings_skills table: ID field, Skill_ID field, Marker_ID(which is the person/group_id), Marker_Type ("Group" or "Person")</p> <p>skills table: ID field, Name field</p> <p>How do I setup the rails association and index the skills of the person or group in the Person model or Group model.</p> <p>my main goal is to refactor my search by indexing the person skills in the person model and searching the name, tags and skills together, instead of searching skills, sharing_skills and people separate like this:</p> <p>This is in my Person model.</p> <pre class="lang-rb prettyprint-override"><code>class Person &lt; ActiveRecord::Base acts_as_taggable acts_as_taggable_on :tags attr_accessible :name, :tag_list validates_presence_of :name belongs_to :marker_image, :class_name =&gt; "Photo", :foreign_key =&gt; "marker_image_id" belongs_to :user extend FriendlyId friendly_id :name, use: [:slugged, :history] define_index do indexes name indexes tag_taggings.tag(:name), :as =&gt; :tags has :id has created_at end </code></pre> <p>This is in my Search Controller</p> <pre class="lang-rb prettyprint-override"><code>#PERSON SEARCH if params[:marker_type].nil? or params[:marker_type].empty? or params[:marker_type] == "Person" #SEARCH NAME, TAGS, (Need to fix skills) conditions = {} %w(name tags).each do |i| i = i.to_sym next unless params[i] conditions[i] = params[i] end person = Person.search_for_ids(params[:search], :conditions =&gt; conditions, :per_page =&gt; 999999) if !person.empty? person_ids &lt;&lt; person end #SEARCH SKILLS IN PERSON MODEL skills = Skill.search_for_ids(params[:search], :per_page =&gt; 99999) check_skills_available_persons = SharingsSkill.search(:conditions =&gt; {:marker_type =&gt; 'Person'}, :with =&gt; {:skill_id =&gt; skills}, :per_page =&gt; 99999) if !check_skills_available_persons.empty? check_people_by_skills = Person.search(:with =&gt; {:id =&gt; check_skills_available_persons.collect{|x|x.marker_id}}) if !check_people_by_skills.empty? check_people_by_skills.each do |p_skill| person_ids &lt;&lt; p_skill.id end end end end </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload