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

decide per index to reconcile class name field #1222

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions lib/thinking_sphinx/configuration/minimum_fields.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ def initialize(indices)
end

def reconcile
return unless no_inheritance_columns?

field_collections.each do |collection|
collection.fields.delete_if do |field|
field.name == 'sphinx_internal_class_name'
Expand All @@ -20,18 +18,19 @@ def reconcile
attr_reader :indices

def field_collections
indices_of_type('plain').collect(&:sources).flatten +
plain_indices_without_inheritance.collect(&:sources).flatten +
indices_of_type('rt')
end

def indices_of_type(type)
indices.select { |index| index.type == type }
end

def no_inheritance_columns?
indices.select { |index|
index.model.table_exists? &&
index.model.column_names.include?(index.model.inheritance_column)
}.empty?
def inheritance_columns?(index)
index.model.table_exists? && index.model.column_names.include?(index.model.inheritance_column)
end

def plain_indices_without_inheritance
indices_of_type('plain').reject(&method(:inheritance_columns?))
end
end
4 changes: 2 additions & 2 deletions spec/thinking_sphinx/configuration/minimum_fields_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@
expect(index_b.fields).to eq([field_b2])
end

it 'keeps the class name fields when one index model has a type column' do
it 'removes the class name fields only for the indices without type column' do
allow(model_a).to receive(:column_names).and_return(['id', 'name', 'type'])
allow(model_b).to receive(:column_names).and_return(['id', 'name'])

subject.reconcile

expect(index_a.sources.first.fields).to eq([field_a1, field_a2])
expect(index_b.fields).to eq([field_b1, field_b2])
expect(index_b.fields).to eq([field_b2])
end
end