Skip to content

Commit

Permalink
Removing type related code
Browse files Browse the repository at this point in the history
  • Loading branch information
picandocodigo committed Apr 16, 2024
1 parent 99fcb36 commit b71d5a9
Show file tree
Hide file tree
Showing 21 changed files with 22 additions and 160 deletions.
2 changes: 1 addition & 1 deletion elasticsearch-model/lib/elasticsearch/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ module Elasticsearch
# # ...
#
module Model
METHODS = [:search, :mapping, :mappings, :settings, :index_name, :document_type, :import]
METHODS = [:search, :mapping, :mappings, :settings, :index_name, :import]

# Adds the `Elasticsearch::Model` functionality to the including class.
#
Expand Down
3 changes: 0 additions & 3 deletions elasticsearch-model/lib/elasticsearch/model/importing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ module ClassMethods
# "index" => {
# "error" => 'FAILED',
# "_index" => "test",
# "_type" => "_doc",
# "_id" => '1',
# "_version" => 1,
# "result" => "foo",
Expand Down Expand Up @@ -138,7 +137,6 @@ def import(options={}, &block)
errors = []
refresh = options.delete(:refresh) || false
target_index = options.delete(:index) || index_name
target_type = options.delete(:type) || document_type
transform = options.delete(:transform) || __transform
pipeline = options.delete(:pipeline)
return_value = options.delete(:return) || 'count'
Expand All @@ -158,7 +156,6 @@ def import(options={}, &block)
__find_in_batches(options) do |batch|
params = {
index: target_index,
type: target_type,
body: __batch_to_bulk(batch, transform)
}

Expand Down
11 changes: 3 additions & 8 deletions elasticsearch-model/lib/elasticsearch/model/indexing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,12 @@ def as_json(options={})
# Wraps the [index mappings](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping.html)
#
class Mappings
attr_accessor :options, :type
attr_accessor :options

# @private
TYPES_WITH_EMBEDDED_PROPERTIES = %w(object nested)

def initialize(type = nil, options={})
@type = type
def initialize(options={})
@options = options
@mapping = {}
end
Expand Down Expand Up @@ -152,7 +151,7 @@ module ClassMethods
# when it doesn't already define them. Use the `__elasticsearch__` proxy otherwise.
#
def mapping(options={}, &block)
@mapping ||= Mappings.new(document_type, options)
@mapping ||= Mappings.new(options)

@mapping.options.update(options) unless options.empty?

Expand Down Expand Up @@ -372,7 +371,6 @@ def index_document(options={})
request = { index: index_name,
id: id,
body: document }
request.merge!(type: document_type) if document_type

client.index(request.merge!(options))
end
Expand All @@ -393,7 +391,6 @@ def index_document(options={})
def delete_document(options={})
request = { index: index_name,
id: self.id }
request.merge!(type: document_type) if document_type

client.delete(request.merge!(options))
end
Expand Down Expand Up @@ -434,7 +431,6 @@ def update_document(options={})
request = { index: index_name,
id: self.id,
body: { doc: attributes } }
request.merge!(type: document_type) if document_type

client.update(request.merge!(options))
end
Expand All @@ -461,7 +457,6 @@ def update_document_attributes(attributes, options={})
request = { index: index_name,
id: self.id,
body: { doc: attributes } }
request.merge!(type: document_type) if document_type

client.update(request.merge!(options))
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,6 @@ def id
@result['_id']
end

# Return document `_type` as `_type`
#
def type
@result['_type']
end

# Delegate methods to `@result` or `@result._source`
#
def method_missing(name, *arguments)
Expand Down
5 changes: 2 additions & 3 deletions elasticsearch-model/lib/elasticsearch/model/searching.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ def initialize(klass, query_or_payload, options={})
@options = options

__index_name = options[:index] || klass.index_name
__document_type = options[:type] || klass.document_type

case
# search query: ...
Expand All @@ -54,9 +53,9 @@ def initialize(klass, query_or_payload, options={})
end

if body
@definition = { index: __index_name, type: __document_type, body: body }.update options
@definition = { index: __index_name, body: body }.update options
else
@definition = { index: __index_name, type: __document_type, q: q }.update options
@definition = { index: __index_name, q: q }.update options
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
end

Article.delete_all
Article.__elasticsearch__.create_index!(force: true, include_type_name: true)
Article.__elasticsearch__.create_index!(force: true)

Article.create!(title: 'Test', body: '', clicks: 1)
Article.create!(title: 'Testing Coding', body: '', clicks: 2)
Expand Down Expand Up @@ -159,19 +159,7 @@
end
end

describe '#id' do

let(:search_result) do
Article.search('title:test')
end

it 'returns the type' do
expect(search_result.results.first.type).to eq('article')
end
end

describe '#each_with_hit' do

let(:search_result) do
Article.search('title:test')
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
end

MyNamespace::Book.delete_all
MyNamespace::Book.__elasticsearch__.create_index!(force: true, include_type_name: true)
MyNamespace::Book.__elasticsearch__.create_index!(force: true)
MyNamespace::Book.create!(title: 'Test')
MyNamespace::Book.__elasticsearch__.refresh_index!
end
Expand All @@ -43,10 +43,6 @@
expect(MyNamespace::Book.index_name).to eq('my_namespace-books')
end

it 'has the proper document type' do
expect(MyNamespace::Book.document_type).to eq('book')
end

it 'saves the document into the index' do
expect(MyNamespace::Book.search('title:test').results.size).to eq(1)
expect(MyNamespace::Book.search('title:test').results.first.title).to eq('Test')
Expand Down
16 changes: 2 additions & 14 deletions elasticsearch-model/spec/elasticsearch/model/importing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ def importing_mixin
describe '#import' do
before do
allow(DummyImportingModel).to receive(:index_name).and_return('foo')
allow(DummyImportingModel).to receive(:document_type).and_return('foo')
allow(DummyImportingModel).to receive(:index_exists?).and_return(true)
allow(DummyImportingModel).to receive(:__batch_to_bulk)
allow(client).to receive(:bulk).and_return(response)
Expand Down Expand Up @@ -148,25 +147,14 @@ def importing_mixin
context 'when a different index name is provided' do
before do
expect(DummyImportingModel).to receive(:client).and_return(client)
expect(client).to receive(:bulk).with(body: nil, index: 'my-new-index', type: 'foo').and_return(response)
expect(client).to receive(:bulk).with(body: nil, index: 'my-new-index').and_return(response)
end

it 'uses the alternate index name' do
expect(DummyImportingModel.import(index: 'my-new-index')).to eq(0)
end
end

context 'when a different document type is provided' do
before do
expect(DummyImportingModel).to receive(:client).and_return(client)
expect(client).to receive(:bulk).with(body: nil, index: 'foo', type: 'my-new-type').and_return(response)
end

it 'uses the alternate index name' do
expect(DummyImportingModel.import(type: 'my-new-type')).to eq(0)
end
end

context 'the transform method' do
before do
expect(DummyImportingModel).to receive(:client).and_return(client)
Expand Down Expand Up @@ -215,7 +203,7 @@ def importing_mixin
context 'when a pipeline is provided as an options' do
before do
expect(DummyImportingModel).to receive(:client).and_return(client)
expect(client).to receive(:bulk).with(body: nil, index: 'foo', type: 'foo', pipeline: 'my-pipeline').and_return(response)
expect(client).to receive(:bulk).with(body: nil, index: 'foo', pipeline: 'my-pipeline').and_return(response)
end

it 'uses the pipeline option' do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class NotFound < Exception; end
end

describe 'the Settings class' do

it 'should be convertible to a hash' do
expect(Elasticsearch::Model::Indexing::Settings.new(foo: 'bar').to_hash).to eq(foo: 'bar')
end
Expand Down
68 changes: 0 additions & 68 deletions elasticsearch-model/spec/elasticsearch/model/naming_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,7 @@ class DummyNamingModelInNamespace
expect(::MyNamespace::DummyNamingModelInNamespace.new.index_name).to eq('my_namespace-dummy_naming_model_in_namespaces')
end

it 'returns nil' do
expect(DummyNamingModel.document_type).to be_nil
expect(DummyNamingModel.new.document_type).to be_nil
end

describe '#index_name' do

context 'when the index name is set on the class' do

before do
Expand Down Expand Up @@ -138,66 +132,4 @@ class DummyNamingModelInNamespace
end
end
end

describe '#document_type' do

it 'returns nil' do
expect(DummyNamingModel.document_type).to be_nil
end

context 'when the method is called with an argument' do

before do
DummyNamingModel.document_type 'foo'
end

it 'changes the document type' do
expect(DummyNamingModel.document_type).to eq('foo')
end
end

context 'when the method is called on an instance' do

let(:instance) do
DummyNamingModel.new
end

before do
instance.document_type 'foobar_d'
end

it 'changes the document type' do
expect(instance.document_type).to eq('foobar_d')
end
end
end

describe '#document_type=' do

context 'when the method is called on the class' do

before do
DummyNamingModel.document_type = 'foo_z'
end

it 'changes the document type' do
expect(DummyNamingModel.document_type).to eq('foo_z')
end
end

context 'when the method is called on an instance' do

let(:instance) do
DummyNamingModel.new
end

before do
instance.document_type = 'foobar_b'
end

it 'changes the document type' do
expect(instance.document_type).to eq('foobar_b')
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class DummyBaseClass

class OriginClass
def self.index_name; 'foo'; end
def self.document_type; 'bar'; end
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
class ModelClass
include ::Kaminari::ConfigurationMethods
def self.index_name; 'foo'; end
def self.document_type; 'bar'; end
end
end

Expand Down Expand Up @@ -58,7 +57,7 @@ def self.document_type; 'bar'; end
context 'when page is called once' do

let(:search_request) do
{ index: index_field, from: 25, size: 25, q: '*', type: type_field}
{ index: index_field, from: 25, size: 25, q: '*' }
end

before do
Expand All @@ -75,11 +74,11 @@ def self.document_type; 'bar'; end
context 'when page is called more than once' do

let(:search_request_one) do
{ index: index_field, from: 25, size: 25, q: '*', type: type_field}
{ index: index_field, from: 25, size: 25, q: '*' }
end

let(:search_request_two) do
{ index: index_field, from: 75, size: 25, q: '*', type: type_field}
{ index: index_field, from: 75, size: 25, q: '*' }
end

before do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
before(:all) do
class OriginClass
def self.index_name; 'foo'; end
def self.document_type; 'bar'; end
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,7 @@
end
end

describe '#type' do

let(:result) do
described_class.new(foo: 'bar', _type: 'baz', _source: { type: 'BAM' })
end

it 'returns the _type field' do
expect(result.type).to eq('baz')
end

it 'provides access to the source type field' do
expect(result._source.type).to eq('BAM')
end
end

describe 'method delegation' do

let(:result) do
described_class.new(foo: 'bar', _source: { bar: { bam: 'baz' } })
end
Expand Down
Loading

0 comments on commit b71d5a9

Please sign in to comment.