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

handle rt and plain indices the same #1249

Merged
merged 1 commit into from
Aug 11, 2023
Merged
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
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',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This got me in trouble originally. index_a should use model_a and index_b should use model_b as far as I understand the intention of the test case.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As much as I can tell, yes, I think you're right! Thanks for this PR :)

: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