-
Notifications
You must be signed in to change notification settings - Fork 470
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Processor for actions on AR instances.
Prompted by discussion in #1215, this provides a direct interface to perform index-related operations on an ActiveRecord index. processor = ThinkingSphinx::Processor.new(instance) processor.delete processor.upsert # real-time indices only
- Loading branch information
Showing
4 changed files
with
65 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# frozen_string_literal: true | ||
|
||
class ThinkingSphinx::Processor | ||
def initialize(instance) | ||
@instance = instance | ||
end | ||
|
||
def delete | ||
return if instance.new_record? | ||
|
||
indices.each { |index| | ||
ThinkingSphinx::Deletion.perform( | ||
index, instance.public_send(index.primary_key) | ||
) | ||
} | ||
end | ||
|
||
def upsert | ||
real_time_indices.each do |index| | ||
ThinkingSphinx::RealTime::Transcriber.new(index).copy instance | ||
end | ||
end | ||
|
||
private | ||
|
||
attr_reader :instance | ||
|
||
def indices | ||
ThinkingSphinx::Configuration.instance.index_set_class.new( | ||
:instances => [instance], :classes => [instance.class] | ||
).to_a | ||
end | ||
|
||
def real_time_indices | ||
indices.select { |index| index.is_a? ThinkingSphinx::RealTime::Index } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters