From f59a5fb50a30874e7d7a24014cda09037acc1c10 Mon Sep 17 00:00:00 2001 From: Semyon Pupkov Date: Thu, 12 Mar 2015 11:13:31 +0500 Subject: [PATCH] Add update_sphinx_fields for any activerecord model --- .../thinking_sphinx/active_record.rb | 33 +++++++++---------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/lib/sphinx/integration/extensions/thinking_sphinx/active_record.rb b/lib/sphinx/integration/extensions/thinking_sphinx/active_record.rb index d6eac50..80392a3 100644 --- a/lib/sphinx/integration/extensions/thinking_sphinx/active_record.rb +++ b/lib/sphinx/integration/extensions/thinking_sphinx/active_record.rb @@ -6,6 +6,21 @@ module Sphinx::Integration::Extensions::ThinkingSphinx::ActiveRecord include Sphinx::Integration::FastFacet end + module ClassMethods + def transmitter + @transmitter ||= Sphinx::Integration::Transmitter.new(self) + end + + # Обновить атрибуты в сфинксе по условию + # + # fields - Hash + # where - Hash + def update_sphinx_fields(fields, where) + define_indexes + transmitter.update_fields(fields, where) + end + end + module TransmitterCallbacks extend ActiveSupport::Concern @@ -13,12 +28,6 @@ module TransmitterCallbacks after_commit :transmitter_create, :on => :create after_commit :transmitter_update, :on => :update after_commit :transmitter_destroy, :on => :destroy - - class << self - def transmitter - @transmitter ||= Sphinx::Integration::Transmitter.new(self) - end - end end def transmitter_create @@ -29,18 +38,6 @@ def transmitter_create def transmitter_destroy self.class.transmitter.delete(self) end - - module ClassMethods - - # Обновить атрибуты в сфинксе по условию - # - # fields - Hash - # where - Hash - def update_sphinx_fields(fields, where) - transmitter.update_fields(fields, where) - end - - end end module ClassMethods