Skip to content

Commit 36a0027

Browse files
committedApr 16, 2024
Removes more type ocurrances
1 parent 283ce0a commit 36a0027

File tree

11 files changed

+12
-163
lines changed

11 files changed

+12
-163
lines changed
 

‎elasticsearch-model/lib/elasticsearch/model/indexing.rb

+1-6
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ def as_json(options={})
5151
class Mappings
5252
attr_accessor :options
5353

54-
# @private
5554
TYPES_WITH_EMBEDDED_PROPERTIES = %w(object nested)
5655

5756
def initialize(options={})
@@ -84,11 +83,7 @@ def indexes(name, options={}, &block)
8483
end
8584

8685
def to_hash
87-
if @type
88-
{ @type.to_sym => @options.merge( properties: @mapping ) }
89-
else
90-
@options.merge( properties: @mapping )
91-
end
86+
@options.merge( properties: @mapping )
9287
end
9388

9489
def as_json(options={})

‎elasticsearch-model/lib/elasticsearch/model/multimodel.rb

-8
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,6 @@ def index_name
8080
models.map { |m| m.index_name }
8181
end
8282

83-
# Get an Array of document types used for retrieving documents when doing a search across multiple models
84-
#
85-
# @return [Array] the list of document types used for retrieving documents
86-
#
87-
def document_type
88-
models.map { |m| m.document_type }.compact.presence
89-
end
90-
9183
# Get the client common for all models
9284
#
9385
# @return Elastic::Transport::Client

‎elasticsearch-model/lib/elasticsearch/model/naming.rb

+7-58
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,10 @@
1717

1818
module Elasticsearch
1919
module Model
20-
21-
# Provides methods for getting and setting index name and document type for the model
20+
# Provides methods for getting and setting index name the model
2221
#
2322
module Naming
24-
25-
DEFAULT_DOC_TYPE = '_doc'.freeze
26-
2723
module ClassMethods
28-
2924
# Get or set the name of the index
3025
#
3126
# @example Set the index name for the `Article` model
@@ -64,46 +59,18 @@ def index_name=(name)
6459
@index_name = name
6560
end
6661

67-
# Get or set the document type
68-
#
69-
# @example Set the document type for the `Article` model
70-
#
71-
# class Article
72-
# document_type "my-article"
73-
# end
74-
#
75-
# @example Directly set the document type for the `Article` model
76-
#
77-
# Article.document_type "my-article"
78-
#
79-
def document_type name=nil
80-
@document_type = name || @document_type || implicit(:document_type)
81-
end
82-
83-
84-
# Set the document type
85-
#
86-
# @see document_type
87-
#
88-
def document_type=(name)
89-
@document_type = name
90-
end
91-
9262
private
9363

94-
def implicit(prop)
95-
self.send("default_#{prop}")
96-
end
97-
98-
def default_index_name
99-
self.model_name.collection.gsub(/\//, '-')
100-
end
64+
def implicit(prop)
65+
self.send("default_#{prop}")
66+
end
10167

102-
def default_document_type; end
68+
def default_index_name
69+
self.model_name.collection.gsub(/\//, '-')
70+
end
10371
end
10472

10573
module InstanceMethods
106-
10774
# Get or set the index name for the model instance
10875
#
10976
# @example Set the index name for an instance of the `Article` model
@@ -129,25 +96,7 @@ def index_name name=nil, &block
12996
def index_name=(name)
13097
@index_name = name
13198
end
132-
133-
# @example Set the document type for an instance of the `Article` model
134-
#
135-
# @article.document_type "my-article"
136-
# @article.__elasticsearch__.update_document
137-
#
138-
def document_type name=nil
139-
@document_type = name || @document_type || self.class.document_type
140-
end
141-
142-
# Set the document type
143-
#
144-
# @see document_type
145-
#
146-
def document_type=(name)
147-
@document_type = name
148-
end
14999
end
150-
151100
end
152101
end
153102
end

‎elasticsearch-model/spec/elasticsearch/model/adapters/active_record/basic_spec.rb

+1-37
Original file line numberDiff line numberDiff line change
@@ -18,43 +18,7 @@
1818
require 'spec_helper'
1919

2020
describe Elasticsearch::Model::Adapter::ActiveRecord do
21-
22-
context 'when a document_type is not defined for the Model' do
23-
before do
24-
ActiveRecord::Schema.define(:version => 1) do
25-
create_table :article_no_types do |t|
26-
t.string :title
27-
t.string :body
28-
t.integer :clicks, :default => 0
29-
t.datetime :created_at, :default => 'NOW()'
30-
end
31-
end
32-
33-
ArticleNoType.delete_all
34-
ArticleNoType.__elasticsearch__.create_index!(force: true)
35-
36-
ArticleNoType.create!(title: 'Test', body: '', clicks: 1)
37-
ArticleNoType.create!(title: 'Testing Coding', body: '', clicks: 2)
38-
ArticleNoType.create!(title: 'Coding', body: '', clicks: 3)
39-
40-
ArticleNoType.__elasticsearch__.refresh_index!
41-
end
42-
43-
describe 'indexing a document' do
44-
45-
let(:search_result) do
46-
ArticleNoType.search('title:test')
47-
end
48-
49-
it 'allows searching for documents' do
50-
expect(search_result.results.size).to be(2)
51-
expect(search_result.records.size).to be(2)
52-
end
53-
end
54-
end
55-
56-
context 'when a document_type is defined for the Model' do
57-
21+
context 'for the Model' do
5822
before(:all) do
5923
ActiveRecord::Schema.define(:version => 1) do
6024
create_table :articles do |t|

‎elasticsearch-model/spec/elasticsearch/model/adapters/multiple_spec.rb

-2
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,11 @@
1818
require 'spec_helper'
1919

2020
describe Elasticsearch::Model::Adapter::Multiple do
21-
2221
before(:all) do
2322
class DummyOne
2423
include Elasticsearch::Model
2524

2625
index_name 'dummy'
27-
document_type 'dummy_one'
2826

2927
def self.find(ids)
3028
ids.map { |id| new(id) }

‎elasticsearch-model/spec/elasticsearch/model/indexing_spec.rb

+1-42
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,6 @@ class NotFound < Exception; end
9494
expect(DummyIndexingModel.mappings).to be_a(Elasticsearch::Model::Indexing::Mappings)
9595
end
9696

97-
it 'does not raise an exception when there is no type passed to the #initialize method' do
98-
expect(Elasticsearch::Model::Indexing::Mappings.new)
99-
end
100-
10197
it 'should be convertible to a hash' do
10298
expect(Elasticsearch::Model::Indexing::Mappings.new({ foo: 'bar' }).to_hash).to eq(expected_mapping_hash)
10399
end
@@ -106,44 +102,7 @@ class NotFound < Exception; end
106102
expect(Elasticsearch::Model::Indexing::Mappings.new({ foo: 'bar' }).as_json).to eq(expected_mapping_hash)
107103
end
108104

109-
context 'when a type is specified' do
110-
let(:mappings) do
111-
Elasticsearch::Model::Indexing::Mappings.new
112-
end
113-
114-
before do
115-
mappings.indexes :foo, { type: 'boolean', include_in_all: false }
116-
mappings.indexes :bar
117-
end
118-
119-
it 'creates the correct mapping definition' do
120-
expect(mappings.to_hash[:properties][:foo][:type]).to eq('boolean')
121-
end
122-
123-
it 'uses text as the default field type' do
124-
expect(mappings.to_hash[:properties][:bar][:type]).to eq('text')
125-
end
126-
127-
context 'when the \'include_type_name\' option is specified' do
128-
let(:mappings) do
129-
Elasticsearch::Model::Indexing::Mappings.new(include_type_name: true)
130-
end
131-
132-
before do
133-
mappings.indexes :foo, { type: 'boolean', include_in_all: false }
134-
end
135-
136-
it 'creates the correct mapping definition' do
137-
expect(mappings.to_hash[:properties][:foo][:type]).to eq('boolean')
138-
end
139-
140-
it 'sets the \'include_type_name\' option' do
141-
expect(mappings.to_hash[:include_type_name]).to eq(true)
142-
end
143-
end
144-
end
145-
146-
context 'when a type is not specified' do
105+
context 'basic mappings' do
147106
let(:mappings) do
148107
Elasticsearch::Model::Indexing::Mappings.new
149108
end

‎elasticsearch-model/spec/elasticsearch/model/multimodel_spec.rb

+2-6
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,17 @@
2424
end
2525

2626
let(:model_1) do
27-
double('Foo', index_name: 'foo_index', document_type: 'foo', to_ary: nil)
27+
double('Foo', index_name: 'foo_index', to_ary: nil)
2828
end
2929

3030
let(:model_2) do
31-
double('Bar', index_name: 'bar_index', document_type: 'bar', to_ary: nil)
31+
double('Bar', index_name: 'bar_index', to_ary: nil)
3232
end
3333

3434
it 'has an index name' do
3535
expect(multimodel.index_name).to eq(['foo_index', 'bar_index'])
3636
end
3737

38-
it 'has an document type' do
39-
expect(multimodel.document_type).to eq(['foo', 'bar'])
40-
end
41-
4238
it 'has a client' do
4339
expect(multimodel.client).to eq(Elasticsearch::Model.client)
4440
end

‎elasticsearch-model/spec/elasticsearch/model/response/aggregations_spec.rb

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
before(:all) do
2323
class OriginClass
2424
def self.index_name; 'foo'; end
25-
def self.document_type; 'bar'; end
2625
end
2726
end
2827

‎elasticsearch-model/spec/elasticsearch/model/response/pagination/will_paginate_spec.rb

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
before(:all) do
2323
class ModelClass
2424
def self.index_name; 'foo'; end
25-
def self.document_type; 'bar'; end
2625

2726
def self.per_page
2827
33

‎elasticsearch-model/spec/elasticsearch/model/response/records_spec.rb

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ def foo; 'BAR'; end
3131

3232
class DummyModel
3333
def self.index_name; 'foo'; end
34-
def self.document_type; 'bar'; end
3534

3635
def self.find(*args)
3736
DummyCollection.new

‎elasticsearch-model/spec/elasticsearch/model/response/results_spec.rb

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
before(:all) do
2323
class OriginClass
2424
def self.index_name; 'foo'; end
25-
def self.document_type; 'bar'; end
2625
end
2726
end
2827

0 commit comments

Comments
 (0)
Please sign in to comment.