Skip to content

Commit

Permalink
Merge pull request #1249 from akostadinov/develop
Browse files Browse the repository at this point in the history
handle rt and plain indices the same
  • Loading branch information
pat authored Aug 11, 2023
2 parents 13d0db2 + 4b7cc68 commit 5caa63f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
16 changes: 8 additions & 8 deletions lib/thinking_sphinx/configuration/minimum_fields.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@ def reconcile
attr_reader :indices

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

def indices_of_type(type)
indices.select { |index| index.type == type }
indices_without_inheritance_of_type('plain').collect(&:sources).flatten +
indices_without_inheritance_of_type('rt')
end

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?))
def indices_without_inheritance_of_type(type)
indices_without_inheritance.select { |index| index.type == type }
end

def indices_without_inheritance
indices.reject(&method(:inheritance_columns?))
end
end
14 changes: 12 additions & 2 deletions spec/thinking_sphinx/configuration/minimum_fields_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
let(:indices) { [index_a, index_b] }
let(:index_a) { double 'Index A', :model => model_a, :type => 'plain',
:sources => [double(:fields => [field_a1, field_a2])] }
let(:index_b) { double 'Index B', :model => model_a, :type => 'rt',
let(:index_b) { double 'Index B', :model => model_b, :type => 'rt',
:fields => [field_b1, field_b2] }
let(:field_a1) { double :name => 'sphinx_internal_class_name' }
let(:field_a2) { double :name => 'name' }
Expand Down Expand Up @@ -38,7 +38,7 @@
expect(index_b.fields).to eq([field_b2])
end

it 'removes the class name fields only for the indices without type column' do
it 'removes the class name fields only for the rt 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'])

Expand All @@ -47,4 +47,14 @@
expect(index_a.sources.first.fields).to eq([field_a1, field_a2])
expect(index_b.fields).to eq([field_b2])
end

it 'removes the class name fields only for the plain indices without type column' do
allow(model_a).to receive(:column_names).and_return(['id', 'name'])
allow(model_b).to receive(:column_names).and_return(['id', 'name', 'type'])

subject.reconcile

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

0 comments on commit 5caa63f

Please sign in to comment.