Prompted by discussions in #1166, this PR changes the IndexSet class to accept :instances alongside the :classes option, which could allow custom subclasses of IndexSet to filter returned indices to a subset as determined by the provided instances.
In particular, if you're sharding your indices, you can return just the specific shard of indices for the instance, rather than all shards:
class IndexSet < ThinkingSphinx::IndexSet
private
def indices
return super if instances.empty?
super.select do |index|
# shard_id or equivalent logic needs to be implemented.
# this would return all core and delta indices for the instance's model,
# filtered by the shard id for the instance.
instances.any? { |instance| index.name[/_#{instance.shard_id}_$/] }
end
end
end
# This line would go in an initialiser:
ThinkingSphinx::Configuration.instance.index_set_class = IndexSet
While it's not necessary moving forward, I'm still passing through the :classes option for anyone who's got a custom IndexSet class that depends on that.
Prompted by discussions in #1166, this PR changes the IndexSet class to accept
:instances
alongside the:classes
option, which could allow custom subclasses of IndexSet to filter returned indices to a subset as determined by the provided instances.In particular, if you're sharding your indices, you can return just the specific shard of indices for the instance, rather than all shards:
While it's not necessary moving forward, I'm still passing through the
:classes
option for anyone who's got a custom IndexSet class that depends on that.