Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use instances for index filtering from callbacks. #1171

Merged
merged 3 commits into from
Jun 22, 2020

Conversation

pat
Copy link
Owner

@pat pat commented Jun 22, 2020

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.

pat added 3 commits June 22, 2020 10:27
We’re going to still pass in the `:classes` option for the moment, for the sake of anyone who’s got a custom IndexSet that relies on that option when managing callbacks.
@pat pat merged commit c418021 into develop Jun 22, 2020
@pat pat deleted the index-instance-filtering branch December 21, 2021 03:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant