@Neodelf

Как с помощью гема Tire искать по по полям связанной таблицы?

Всем привет.
Есть модель с таким кодом:
mapping do
  indexes :id, type: 'integer'
  indexes :name, type: 'string'
  indexes :address, type: 'string'
  indexes :offices_pub_count, type: 'integer'

  indexes :offices do
    indexes :retail, type: 'boolean'
  end
end

def as_indexed_json(options={})
  to_json(methods: [:offices_pub_count],
    include: { offices: { only: [:text,:desc,:floor,:inner_info,:decoration,:fire_safety,:air_conditioning,:parking,:planning,
                                           :commercial_terms,:operation_cost_id, :retail] } }

def offices_pub_count
  offices_pub.size
end

has_many :offices, :dependent => :destroy
has_many :offices_pub, class_name: 'Office', foreign_key: 'business_center_id', conditions: {published: true}


Но вот поиск с фильтрацией не полю офисов дает пустой массив:
BusinessCenter.search(:load => { :include => 'offices' }) do
  query { string '*' }
  filter :term, "offices.retail" => true
end

Кто как решал такую задачу?
P.S. Фактически, пример по ссылке https://gist.github.com/karmi/3200212 не работает
  • Вопрос задан
  • 123 просмотра
Пригласить эксперта
Ответы на вопрос 1
Able1991
@Able1991
Пишу на рельсах
А это не забыли, как в примере?
class Chapter < ActiveRecord::Base
  # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  # Do not forget to automatically `touch` parent object from associations
  belongs_to :book, touch: true
  # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
end

и в модели по которой ищем
after_touch() { tire.update_index }
При добавлении связанного объекта должен обновится индекс по записи
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы