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
# Could perhaps live in app/lib, or app/middleware? | |
class TenancyMiddleware < ThinkingSphinx::Middlewares::Middleware | |
def call(contexts) | |
contexts.each do |context| | |
Inner.new(context).call | |
end | |
app.call contexts | |
end | |
class Inner | |
def initialize(context) | |
@context = context | |
end | |
def call | |
tenant = options[:tenant] | |
return unless tenant | |
classes = options[:classes] || [] | |
indices = options[:indices] || [] | |
set = ThinkingSphinx::IndexSet.new(classes, indices) | |
options[:classes] = [] | |
options[:indices] = set.select { |index| | |
index.name[/_#{tenant.id}_(core|delta)$/] | |
} | |
end | |
private | |
def options | |
@context.search.options | |
end | |
end | |
end | |
# Put this line in an initializer: | |
ThinkingSphinx::Middlewares::DEFAULT.insert(0, TenancyMiddleware) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Pat,
Correction:
instead of
there should be