postgresql - Rails with Sunspot add Child Model Attributes -
so, have been messing hours , think have tried thats been posted on issue already. first question.
so, trying search models (locations) :branch_name, :branch_address1, etc child model (employees) :first_name used within model own attribute. desired effect locations (as results) return if locations employee name in search query. i'm trying achieve code this:
class location < activerecord::base belongs_to :partner has_many :employees, dependent: :destroy validates_presence_of :branch_name, :branch_address1, :branch_country, :branch_zip_code accepts_nested_attributes_for :employees, allow_destroy: true, :reject_if > proc { |attributes| attributes['first_name'].blank? } searchable text :branch_name, :branch_address1, :branch_city, :branch_zip_code text :employee_attributes :first_name if :employee_attributes end end end end
use parent model (partners) name but, couldn't work either.
could make new column in locations table capture every new employee name, or can search within models children?
i have used solr rails, had encountered similar problems. asked new column, had added new field solr
pseudo code
searchable text :first_name, :stored => true string :partner_name, :stored => true partner.name end end
please note, stored fields increase cost.
in case, had fire multiple queries took 47 seconds, storing value helped me avoid multiple queries, single query took 5 seconds.
you need re-index results.
Comments
Post a Comment