elasticsearch-model 5.1.0 → 6.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +5 -0
- data/README.md +18 -11
- data/Rakefile +27 -36
- data/elasticsearch-model.gemspec +5 -5
- data/examples/activerecord_custom_analyzer.rb +135 -0
- data/examples/activerecord_mapping_completion.rb +3 -18
- data/examples/datamapper_article.rb +11 -1
- data/gemfiles/3.0.gemfile +6 -1
- data/gemfiles/4.0.gemfile +7 -1
- data/gemfiles/5.0.gemfile +7 -1
- data/lib/elasticsearch/model/adapters/active_record.rb +7 -23
- data/lib/elasticsearch/model/adapters/mongoid.rb +10 -3
- data/lib/elasticsearch/model/importing.rb +1 -1
- data/lib/elasticsearch/model/indexing.rb +6 -4
- data/lib/elasticsearch/model/naming.rb +9 -2
- data/lib/elasticsearch/model/response/aggregations.rb +1 -1
- data/lib/elasticsearch/model/response/base.rb +3 -2
- data/lib/elasticsearch/model/response/pagination/kaminari.rb +109 -0
- data/lib/elasticsearch/model/response/pagination/will_paginate.rb +95 -0
- data/lib/elasticsearch/model/response/pagination.rb +2 -192
- data/lib/elasticsearch/model/response/result.rb +1 -1
- data/lib/elasticsearch/model/response/suggestions.rb +1 -1
- data/lib/elasticsearch/model/response.rb +11 -10
- data/lib/elasticsearch/model/version.rb +1 -1
- data/lib/elasticsearch/model.rb +15 -8
- data/spec/elasticsearch/model/adapter_spec.rb +119 -0
- data/spec/elasticsearch/model/adapters/active_record/associations_spec.rb +334 -0
- data/spec/elasticsearch/model/adapters/active_record/basic_spec.rb +340 -0
- data/spec/elasticsearch/model/adapters/active_record/dynamic_index_name_spec.rb +18 -0
- data/spec/elasticsearch/model/adapters/active_record/import_spec.rb +187 -0
- data/spec/elasticsearch/model/adapters/active_record/multi_model_spec.rb +110 -0
- data/spec/elasticsearch/model/adapters/active_record/namespaced_model_spec.rb +38 -0
- data/spec/elasticsearch/model/adapters/active_record/pagination_spec.rb +315 -0
- data/spec/elasticsearch/model/adapters/active_record/parent_child_spec.rb +75 -0
- data/spec/elasticsearch/model/adapters/active_record/serialization_spec.rb +61 -0
- data/spec/elasticsearch/model/adapters/active_record_spec.rb +207 -0
- data/spec/elasticsearch/model/adapters/default_spec.rb +41 -0
- data/spec/elasticsearch/model/adapters/mongoid/basic_spec.rb +267 -0
- data/spec/elasticsearch/model/adapters/mongoid/multi_model_spec.rb +66 -0
- data/spec/elasticsearch/model/adapters/mongoid_spec.rb +235 -0
- data/spec/elasticsearch/model/adapters/multiple_spec.rb +125 -0
- data/spec/elasticsearch/model/callbacks_spec.rb +33 -0
- data/spec/elasticsearch/model/client_spec.rb +66 -0
- data/spec/elasticsearch/model/hash_wrapper_spec.rb +12 -0
- data/spec/elasticsearch/model/importing_spec.rb +214 -0
- data/spec/elasticsearch/model/indexing_spec.rb +918 -0
- data/spec/elasticsearch/model/module_spec.rb +101 -0
- data/spec/elasticsearch/model/multimodel_spec.rb +55 -0
- data/spec/elasticsearch/model/naming_inheritance_spec.rb +184 -0
- data/spec/elasticsearch/model/naming_spec.rb +186 -0
- data/spec/elasticsearch/model/proxy_spec.rb +107 -0
- data/spec/elasticsearch/model/response/aggregations_spec.rb +66 -0
- data/spec/elasticsearch/model/response/base_spec.rb +90 -0
- data/spec/elasticsearch/model/response/pagination/kaminari_spec.rb +410 -0
- data/spec/elasticsearch/model/response/pagination/will_paginate_spec.rb +262 -0
- data/spec/elasticsearch/model/response/records_spec.rb +118 -0
- data/spec/elasticsearch/model/response/response_spec.rb +131 -0
- data/spec/elasticsearch/model/response/result_spec.rb +122 -0
- data/spec/elasticsearch/model/response/results_spec.rb +56 -0
- data/spec/elasticsearch/model/searching_search_request_spec.rb +112 -0
- data/spec/elasticsearch/model/searching_spec.rb +49 -0
- data/spec/elasticsearch/model/serializing_spec.rb +22 -0
- data/spec/spec_helper.rb +161 -0
- data/spec/support/app/answer.rb +33 -0
- data/spec/support/app/article.rb +22 -0
- data/spec/support/app/article_for_pagination.rb +12 -0
- data/spec/support/app/article_with_custom_serialization.rb +13 -0
- data/spec/support/app/article_with_dynamic_index_name.rb +15 -0
- data/spec/support/app/author.rb +9 -0
- data/spec/support/app/authorship.rb +4 -0
- data/spec/support/app/category.rb +3 -0
- data/spec/support/app/comment.rb +3 -0
- data/spec/support/app/episode.rb +11 -0
- data/spec/support/app/image.rb +19 -0
- data/spec/support/app/import_article.rb +12 -0
- data/spec/support/app/mongoid_article.rb +21 -0
- data/spec/support/app/namespaced_book.rb +10 -0
- data/spec/support/app/parent_and_child_searchable.rb +24 -0
- data/spec/support/app/post.rb +14 -0
- data/spec/support/app/question.rb +27 -0
- data/spec/support/app/searchable.rb +48 -0
- data/spec/support/app/series.rb +11 -0
- data/spec/support/app.rb +21 -0
- data/spec/support/model.json +1 -0
- metadata +134 -90
- data/test/integration/active_record_associations_parent_child_test.rb +0 -147
- data/test/integration/active_record_associations_test.rb +0 -339
- data/test/integration/active_record_basic_test.rb +0 -251
- data/test/integration/active_record_custom_serialization_test.rb +0 -67
- data/test/integration/active_record_import_test.rb +0 -115
- data/test/integration/active_record_namespaced_model_test.rb +0 -54
- data/test/integration/active_record_pagination_test.rb +0 -149
- data/test/integration/dynamic_index_name_test.rb +0 -52
- data/test/integration/mongoid_basic_test.rb +0 -176
- data/test/integration/multiple_models_test.rb +0 -176
- data/test/support/model.json +0 -1
- data/test/test_helper.rb +0 -92
- data/test/unit/adapter_active_record_test.rb +0 -157
- data/test/unit/adapter_default_test.rb +0 -41
- data/test/unit/adapter_mongoid_test.rb +0 -104
- data/test/unit/adapter_multiple_test.rb +0 -106
- data/test/unit/adapter_test.rb +0 -69
- data/test/unit/callbacks_test.rb +0 -31
- data/test/unit/client_test.rb +0 -27
- data/test/unit/hash_wrapper_test.rb +0 -13
- data/test/unit/importing_test.rb +0 -203
- data/test/unit/indexing_test.rb +0 -687
- data/test/unit/module_test.rb +0 -68
- data/test/unit/multimodel_test.rb +0 -38
- data/test/unit/naming_inheritance_test.rb +0 -94
- data/test/unit/naming_test.rb +0 -103
- data/test/unit/proxy_test.rb +0 -98
- data/test/unit/response_aggregations_test.rb +0 -46
- data/test/unit/response_base_test.rb +0 -40
- data/test/unit/response_pagination_kaminari_test.rb +0 -433
- data/test/unit/response_pagination_will_paginate_test.rb +0 -398
- data/test/unit/response_records_test.rb +0 -91
- data/test/unit/response_result_test.rb +0 -90
- data/test/unit/response_results_test.rb +0 -31
- data/test/unit/response_test.rb +0 -104
- data/test/unit/searching_search_request_test.rb +0 -78
- data/test/unit/searching_test.rb +0 -41
- data/test/unit/serializing_test.rb +0 -17
- /data/{test → spec}/support/model.yml +0 -0
data/test/unit/response_test.rb
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
require 'test_helper'
|
|
2
|
-
|
|
3
|
-
class Elasticsearch::Model::ResponseTest < Test::Unit::TestCase
|
|
4
|
-
context "Response" do
|
|
5
|
-
class OriginClass
|
|
6
|
-
def self.index_name; 'foo'; end
|
|
7
|
-
def self.document_type; 'bar'; end
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
RESPONSE = { 'took' => '5', 'timed_out' => false, '_shards' => {'one' => 'OK'}, 'hits' => { 'hits' => [] },
|
|
11
|
-
'aggregations' => {'foo' => {'bar' => 10}},
|
|
12
|
-
'suggest' => {'my_suggest' => [ { 'text' => 'foo', 'options' => [ { 'text' => 'Foo', 'score' => 2.0 }, { 'text' => 'Bar', 'score' => 1.0 } ] } ]}}
|
|
13
|
-
|
|
14
|
-
setup do
|
|
15
|
-
@search = Elasticsearch::Model::Searching::SearchRequest.new OriginClass, '*'
|
|
16
|
-
@search.stubs(:execute!).returns(RESPONSE)
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
should "access klass, response, took, timed_out, shards" do
|
|
20
|
-
response = Elasticsearch::Model::Response::Response.new OriginClass, @search
|
|
21
|
-
|
|
22
|
-
assert_equal OriginClass, response.klass
|
|
23
|
-
assert_equal @search, response.search
|
|
24
|
-
assert_equal RESPONSE, response.response
|
|
25
|
-
assert_equal '5', response.took
|
|
26
|
-
assert_equal false, response.timed_out
|
|
27
|
-
assert_equal 'OK', response.shards.one
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
should "wrap the raw Hash response in a HashWrapper" do
|
|
31
|
-
@search = Elasticsearch::Model::Searching::SearchRequest.new OriginClass, '*'
|
|
32
|
-
@search.stubs(:execute!).returns({'hits' => { 'hits' => [] }, 'aggregations' => { 'dates' => 'FOO' }})
|
|
33
|
-
|
|
34
|
-
response = Elasticsearch::Model::Response::Response.new OriginClass, @search
|
|
35
|
-
|
|
36
|
-
assert_respond_to response.response, :aggregations
|
|
37
|
-
assert_equal 'FOO', response.response.aggregations.dates
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
should "load and access the results" do
|
|
41
|
-
@search.expects(:execute!).returns(RESPONSE)
|
|
42
|
-
|
|
43
|
-
response = Elasticsearch::Model::Response::Response.new OriginClass, @search
|
|
44
|
-
assert_instance_of Elasticsearch::Model::Response::Results, response.results
|
|
45
|
-
assert_equal 0, response.size
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
should "load and access the records" do
|
|
49
|
-
@search.expects(:execute!).returns(RESPONSE)
|
|
50
|
-
|
|
51
|
-
response = Elasticsearch::Model::Response::Response.new OriginClass, @search
|
|
52
|
-
assert_instance_of Elasticsearch::Model::Response::Records, response.records
|
|
53
|
-
assert_equal 0, response.size
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
should "delegate Enumerable methods to results" do
|
|
57
|
-
@search.expects(:execute!).returns(RESPONSE)
|
|
58
|
-
|
|
59
|
-
response = Elasticsearch::Model::Response::Response.new OriginClass, @search
|
|
60
|
-
assert response.empty?
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
should "be initialized lazily" do
|
|
64
|
-
@search.expects(:execute!).never
|
|
65
|
-
|
|
66
|
-
Elasticsearch::Model::Response::Response.new OriginClass, @search
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
should "access the aggregations" do
|
|
70
|
-
@search.expects(:execute!).returns(RESPONSE)
|
|
71
|
-
|
|
72
|
-
response = Elasticsearch::Model::Response::Response.new OriginClass, @search
|
|
73
|
-
assert_respond_to response, :aggregations
|
|
74
|
-
assert_kind_of Hashie::Mash, response.aggregations.foo
|
|
75
|
-
assert_equal 10, response.aggregations.foo.bar
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
should "access the suggest" do
|
|
79
|
-
@search.expects(:execute!).returns(RESPONSE)
|
|
80
|
-
|
|
81
|
-
response = Elasticsearch::Model::Response::Response.new OriginClass, @search
|
|
82
|
-
|
|
83
|
-
assert_respond_to response, :suggestions
|
|
84
|
-
assert_kind_of Hashie::Mash, response.suggestions
|
|
85
|
-
assert_equal 'Foo', response.suggestions.my_suggest.first.options.first.text
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
should "return array of terms from the suggestions" do
|
|
89
|
-
@search.expects(:execute!).returns(RESPONSE)
|
|
90
|
-
response = Elasticsearch::Model::Response::Response.new OriginClass, @search
|
|
91
|
-
|
|
92
|
-
assert_not_empty response.suggestions
|
|
93
|
-
assert_equal [ 'Foo', 'Bar' ], response.suggestions.terms
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
should "return empty array as suggest terms when there are no suggestions" do
|
|
97
|
-
@search.expects(:execute!).returns({})
|
|
98
|
-
response = Elasticsearch::Model::Response::Response.new OriginClass, @search
|
|
99
|
-
|
|
100
|
-
assert_empty response.suggestions
|
|
101
|
-
assert_equal [], response.suggestions.terms
|
|
102
|
-
end
|
|
103
|
-
end
|
|
104
|
-
end
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
require 'test_helper'
|
|
2
|
-
|
|
3
|
-
class Elasticsearch::Model::SearchRequestTest < Test::Unit::TestCase
|
|
4
|
-
context "SearchRequest class" do
|
|
5
|
-
class ::DummySearchingModel
|
|
6
|
-
extend Elasticsearch::Model::Searching::ClassMethods
|
|
7
|
-
|
|
8
|
-
def self.index_name; 'foo'; end
|
|
9
|
-
def self.document_type; 'bar'; end
|
|
10
|
-
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
setup do
|
|
14
|
-
@client = mock('client')
|
|
15
|
-
DummySearchingModel.stubs(:client).returns(@client)
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
should "pass the search definition as a simple query" do
|
|
19
|
-
@client.expects(:search).with do |params|
|
|
20
|
-
assert_equal 'foo', params[:q]
|
|
21
|
-
true
|
|
22
|
-
end
|
|
23
|
-
.returns({})
|
|
24
|
-
|
|
25
|
-
s = Elasticsearch::Model::Searching::SearchRequest.new ::DummySearchingModel, 'foo'
|
|
26
|
-
s.execute!
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
should "pass the search definition as a Hash" do
|
|
30
|
-
@client.expects(:search).with do |params|
|
|
31
|
-
assert_equal( {foo: 'bar'}, params[:body] )
|
|
32
|
-
true
|
|
33
|
-
end
|
|
34
|
-
.returns({})
|
|
35
|
-
|
|
36
|
-
s = Elasticsearch::Model::Searching::SearchRequest.new ::DummySearchingModel, foo: 'bar'
|
|
37
|
-
s.execute!
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
should "pass the search definition as a JSON string" do
|
|
41
|
-
@client.expects(:search).with do |params|
|
|
42
|
-
assert_equal( '{"foo":"bar"}', params[:body] )
|
|
43
|
-
true
|
|
44
|
-
end
|
|
45
|
-
.returns({})
|
|
46
|
-
|
|
47
|
-
s = Elasticsearch::Model::Searching::SearchRequest.new ::DummySearchingModel, '{"foo":"bar"}'
|
|
48
|
-
s.execute!
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
should "pass the search definition as an object which responds to to_hash" do
|
|
52
|
-
class MySpecialQueryBuilder
|
|
53
|
-
def to_hash; {foo: 'bar'}; end
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
@client.expects(:search).with do |params|
|
|
57
|
-
assert_equal( {foo: 'bar'}, params[:body] )
|
|
58
|
-
true
|
|
59
|
-
end
|
|
60
|
-
.returns({})
|
|
61
|
-
|
|
62
|
-
s = Elasticsearch::Model::Searching::SearchRequest.new ::DummySearchingModel, MySpecialQueryBuilder.new
|
|
63
|
-
s.execute!
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
should "pass the options to the client" do
|
|
67
|
-
@client.expects(:search).with do |params|
|
|
68
|
-
assert_equal 'foo', params[:q]
|
|
69
|
-
assert_equal 15, params[:size]
|
|
70
|
-
true
|
|
71
|
-
end
|
|
72
|
-
.returns({})
|
|
73
|
-
|
|
74
|
-
s = Elasticsearch::Model::Searching::SearchRequest.new ::DummySearchingModel, 'foo', size: 15
|
|
75
|
-
s.execute!
|
|
76
|
-
end
|
|
77
|
-
end
|
|
78
|
-
end
|
data/test/unit/searching_test.rb
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
require 'test_helper'
|
|
2
|
-
|
|
3
|
-
class Elasticsearch::Model::SearchingTest < Test::Unit::TestCase
|
|
4
|
-
context "Searching module" do
|
|
5
|
-
class ::DummySearchingModel
|
|
6
|
-
extend Elasticsearch::Model::Searching::ClassMethods
|
|
7
|
-
|
|
8
|
-
def self.index_name; 'foo'; end
|
|
9
|
-
def self.document_type; 'bar'; end
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
setup do
|
|
13
|
-
@client = mock('client')
|
|
14
|
-
DummySearchingModel.stubs(:client).returns(@client)
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
should "have the search method" do
|
|
18
|
-
assert_respond_to DummySearchingModel, :search
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
should "initialize the search object" do
|
|
22
|
-
Elasticsearch::Model::Searching::SearchRequest
|
|
23
|
-
.expects(:new).with do |klass, query, options|
|
|
24
|
-
assert_equal DummySearchingModel, klass
|
|
25
|
-
assert_equal 'foo', query
|
|
26
|
-
assert_equal({default_operator: 'AND'}, options)
|
|
27
|
-
true
|
|
28
|
-
end
|
|
29
|
-
.returns( stub('search') )
|
|
30
|
-
|
|
31
|
-
DummySearchingModel.search 'foo', default_operator: 'AND'
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
should "not execute the search" do
|
|
35
|
-
Elasticsearch::Model::Searching::SearchRequest
|
|
36
|
-
.expects(:new).returns( mock('search').expects(:execute!).never )
|
|
37
|
-
|
|
38
|
-
DummySearchingModel.search 'foo'
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
end
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
require 'test_helper'
|
|
2
|
-
|
|
3
|
-
class Elasticsearch::Model::SerializingTest < Test::Unit::TestCase
|
|
4
|
-
context "Serializing module" do
|
|
5
|
-
class DummyClass
|
|
6
|
-
include Elasticsearch::Model::Serializing::InstanceMethods
|
|
7
|
-
|
|
8
|
-
def as_json(options={})
|
|
9
|
-
'HASH'
|
|
10
|
-
end
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
should "delegate to as_json by default" do
|
|
14
|
-
assert_equal 'HASH', DummyClass.new.as_indexed_json
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
end
|
|
File without changes
|