Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
# 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)
@ilkon

Hi Pat,

Correction:
instead of

options[:indices] = set.select { |index|
        index.name[/_#{tenant.id}_(core|delta)$/]
}

there should be

options[:indices] = set.select { |index|
        index.name[/_#{tenant.id}_(core|delta)$/]
}.map(&:name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.