Skip to content

Commit

Permalink
Add update_sphinx_fields for any activerecord model
Browse files Browse the repository at this point in the history
  • Loading branch information
artofhuman committed Mar 12, 2015
1 parent b2161d3 commit f59a5fb
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions lib/sphinx/integration/extensions/thinking_sphinx/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,28 @@ 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

included do
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
Expand All @@ -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
Expand Down

0 comments on commit f59a5fb

Please sign in to comment.