elastic_record 1.4.2 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/README.rdoc +8 -8
- data/elastic_record.gemspec +2 -2
- data/lib/elastic_record/index/deferred.rb +2 -2
- data/lib/elastic_record/index/documents.rb +2 -2
- data/lib/elastic_record/index/manage.rb +13 -7
- data/lib/elastic_record/index/mapping.rb +6 -3
- data/lib/elastic_record/index/percolator.rb +12 -14
- data/lib/elastic_record/index/warmer.rb +7 -7
- data/lib/elastic_record/index.rb +1 -1
- data/lib/elastic_record/relation/none.rb +4 -0
- data/lib/elastic_record/relation/search_methods.rb +14 -0
- data/lib/elastic_record/relation/value_methods.rb +1 -1
- data/lib/elastic_record/relation.rb +4 -0
- data/test/elastic_record/callbacks_test.rb +1 -1
- data/test/elastic_record/config_test.rb +1 -1
- data/test/elastic_record/connection_test.rb +1 -1
- data/test/elastic_record/index/configurator_test.rb +1 -1
- data/test/elastic_record/index/documents_test.rb +6 -6
- data/test/elastic_record/index/manage_test.rb +3 -3
- data/test/elastic_record/index/mapping_test.rb +4 -6
- data/test/elastic_record/index/percolator_test.rb +14 -3
- data/test/elastic_record/index/settings_test.rb +1 -1
- data/test/elastic_record/index/warmer_test.rb +1 -1
- data/test/elastic_record/index_test.rb +1 -1
- data/test/elastic_record/integration/active_record_test.rb +2 -2
- data/test/elastic_record/lucene_test.rb +1 -1
- data/test/elastic_record/model_test.rb +1 -1
- data/test/elastic_record/railties/controller_runtime_test.rb +1 -1
- data/test/elastic_record/relation/admin_test.rb +2 -2
- data/test/elastic_record/relation/batches_test.rb +1 -1
- data/test/elastic_record/relation/delegation_test.rb +1 -1
- data/test/elastic_record/relation/finder_methods_test.rb +15 -2
- data/test/elastic_record/relation/merging_test.rb +1 -1
- data/test/elastic_record/relation/none_test.rb +3 -2
- data/test/elastic_record/relation/search_methods_test.rb +13 -14
- data/test/elastic_record/relation_test.rb +10 -1
- data/test/elastic_record/searching_test.rb +1 -1
- data/test/helper.rb +10 -12
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6e7ce3ca4166690dfd09ab6072e1cb1d84e5efda
|
4
|
+
data.tar.gz: 61c4da83fe674d7c95a63e475ff3ba39daedde11
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9e463040d4d6ca0393b8ebdd54bf6df62366e6d65664ad8a46c1fc2eae4d51e805f21e643ba2f2b245cfe2637d95ad48fda1b12a5a8a306139399db660e3ed0d
|
7
|
+
data.tar.gz: 1078110a75c4837be1e422fecb8a05efcaf8a953198435baeb0ebf8988c75d32b9eb5370dd930f06a8c19768ae16d2d6f5bbb003a403cc23a45df2e1b0213a2f
|
data/.travis.yml
CHANGED
data/README.rdoc
CHANGED
@@ -7,7 +7,7 @@ ElasticRecord is an elasticsearch ORM.
|
|
7
7
|
== Setup
|
8
8
|
|
9
9
|
The usual Gemfile addition:
|
10
|
-
|
10
|
+
|
11
11
|
gem 'elastic_record'
|
12
12
|
|
13
13
|
|
@@ -73,17 +73,17 @@ To change the 'size' and 'from' values of a query, use offset and limit:
|
|
73
73
|
|
74
74
|
search.limit(40).offset(80) # Creates a query with {size: 40, from: 80}
|
75
75
|
|
76
|
-
===
|
76
|
+
=== Aggregations
|
77
77
|
|
78
|
-
|
78
|
+
Aggregations are added with the aggregate method:
|
79
79
|
|
80
|
-
search.
|
80
|
+
search.aggregate('popular_colors' => {'terms' => {'field' => 'color'}})
|
81
81
|
|
82
|
-
It is important to note that adding
|
82
|
+
It is important to note that adding aggregations to a query is different than retrieving the results of the query:
|
83
83
|
|
84
|
-
search = search.
|
85
|
-
search.
|
86
|
-
#=> {"
|
84
|
+
search = search.aggregate('popular_colors' => {'terms' => {'field' => 'color'}})
|
85
|
+
search.aggregations
|
86
|
+
#=> {"popular_colors" => {"buckets" => ...}}
|
87
87
|
|
88
88
|
=== Getting Results
|
89
89
|
|
data/elastic_record.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = 'elastic_record'
|
5
|
-
s.version = '
|
5
|
+
s.version = '2.0.0'
|
6
6
|
s.summary = 'Use Elastic Search with your objects'
|
7
7
|
s.description = 'Find your records with elastic search'
|
8
8
|
|
@@ -18,6 +18,6 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.files = `git ls-files`.split("\n")
|
19
19
|
s.test_files = `git ls-files -- {test}/*`.split("\n")
|
20
20
|
|
21
|
-
s.add_dependency 'arelastic', '>= 0.
|
21
|
+
s.add_dependency 'arelastic', '>= 0.6.0'
|
22
22
|
s.add_dependency 'activemodel'
|
23
23
|
end
|
@@ -23,7 +23,7 @@ module ElasticRecord
|
|
23
23
|
if writes_made
|
24
24
|
begin
|
25
25
|
index.disable_deferring!
|
26
|
-
index.delete_by_query match_all: {}
|
26
|
+
index.delete_by_query query: {match_all: {}}
|
27
27
|
ensure
|
28
28
|
index.enable_deferring!
|
29
29
|
end
|
@@ -84,4 +84,4 @@ module ElasticRecord
|
|
84
84
|
end
|
85
85
|
end
|
86
86
|
end
|
87
|
-
end
|
87
|
+
end
|
@@ -71,16 +71,22 @@ module ElasticRecord
|
|
71
71
|
end
|
72
72
|
|
73
73
|
def aliased_names
|
74
|
-
|
75
|
-
|
74
|
+
if (index_names = all_names).any?
|
75
|
+
json = connection.json_get "/#{index_names.join(',')}/_alias"
|
76
|
+
json.keys.select do |index_name|
|
77
|
+
json[index_name]['aliases'].keys.include?(alias_name)
|
78
|
+
end
|
79
|
+
else
|
80
|
+
[]
|
81
|
+
end
|
76
82
|
end
|
77
83
|
|
78
84
|
def all_names
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
85
|
+
connection.json_get("/#{alias_name}/_mapping/#{type}/").keys
|
86
|
+
rescue
|
87
|
+
# TODO: In ES 1.4, this returns empty rather than a 404
|
88
|
+
[]
|
83
89
|
end
|
84
90
|
end
|
85
91
|
end
|
86
|
-
end
|
92
|
+
end
|
@@ -8,9 +8,12 @@ module ElasticRecord
|
|
8
8
|
def update_mapping(index_name = alias_name)
|
9
9
|
connection.json_put "/#{index_name}/#{type}/_mapping", type => mapping
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
def get_mapping(index_name = alias_name)
|
13
|
-
connection.json_get "/#{index_name}/#{type}/_mapping"
|
13
|
+
json = connection.json_get "/#{index_name}/#{type}/_mapping"
|
14
|
+
unless json.empty?
|
15
|
+
json.values.first['mappings']
|
16
|
+
end
|
14
17
|
end
|
15
18
|
|
16
19
|
def delete_mapping(index_name = alias_name)
|
@@ -45,4 +48,4 @@ module ElasticRecord
|
|
45
48
|
end
|
46
49
|
end
|
47
50
|
end
|
48
|
-
end
|
51
|
+
end
|
@@ -2,42 +2,40 @@ module ElasticRecord
|
|
2
2
|
class Index
|
3
3
|
module Percolator
|
4
4
|
def create_percolator(name, elastic_query)
|
5
|
-
|
6
|
-
create percolator_index_name
|
7
|
-
end
|
8
|
-
connection.json_put "/_percolator/#{percolator_index_name}/#{name}", elastic_query
|
5
|
+
connection.json_put "/#{percolator_name}/.percolator/#{name}", elastic_query
|
9
6
|
end
|
10
7
|
|
11
8
|
def delete_percolator(name)
|
12
|
-
connection.json_delete "
|
9
|
+
connection.json_delete "/#{percolator_name}/.percolator/#{name}"
|
13
10
|
end
|
14
11
|
|
15
12
|
def percolator_exists?(name)
|
16
|
-
|
13
|
+
connection.head("/#{percolator_name}/.percolator/#{name}") == '200'
|
17
14
|
end
|
18
15
|
|
19
16
|
def get_percolator(name)
|
20
|
-
json = connection.json_get("
|
21
|
-
json['_source'] if json['
|
17
|
+
json = connection.json_get("/#{percolator_name}/.percolator/#{name}")
|
18
|
+
json['_source'] if json['found']
|
22
19
|
end
|
23
20
|
|
24
21
|
def percolate(document)
|
25
|
-
connection.json_get("/#{
|
22
|
+
hits = connection.json_get("/#{percolator_name}/#{type}/_percolate", 'doc' => document)['matches']
|
23
|
+
hits.map { |hits| hits['_id']}
|
26
24
|
end
|
27
25
|
|
28
26
|
def all_percolators
|
29
|
-
if hits = connection.json_get("
|
27
|
+
if hits = connection.json_get("/#{percolator_name}/.percolator/_search?q=*&size=500")['hits']
|
30
28
|
hits['hits'].map { |hit| hit['_id'] }
|
31
29
|
end
|
32
30
|
end
|
33
31
|
|
34
32
|
def reset_percolators
|
35
|
-
delete(
|
36
|
-
create(
|
33
|
+
delete(percolator_name) if exists?(percolator_name)
|
34
|
+
create(percolator_name)
|
37
35
|
end
|
38
36
|
|
39
|
-
def
|
40
|
-
|
37
|
+
def percolator_name
|
38
|
+
"#{alias_name}_percolator"
|
41
39
|
end
|
42
40
|
end
|
43
41
|
end
|
@@ -6,19 +6,19 @@ module ElasticRecord
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def delete_warmer(name)
|
9
|
-
connection.json_delete "/#{alias_name}
|
9
|
+
connection.json_delete "/#{alias_name}/_warmer/#{name}"
|
10
10
|
end
|
11
11
|
|
12
12
|
def get_warmer(name)
|
13
|
-
connection.json_get("/#{alias_name}/#{type}/_warmer/#{name}")
|
13
|
+
json = connection.json_get("/#{alias_name}/#{type}/_warmer/#{name}")
|
14
|
+
if json.any?
|
15
|
+
json.values.first['warmers'][name]
|
16
|
+
end
|
14
17
|
end
|
15
18
|
|
16
19
|
def warmer_exists?(name)
|
17
|
-
get_warmer(name)
|
18
|
-
true
|
19
|
-
rescue ElasticRecord::ConnectionError
|
20
|
-
false
|
20
|
+
!get_warmer(name).nil?
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
24
|
-
end
|
24
|
+
end
|
data/lib/elastic_record/index.rb
CHANGED
@@ -92,6 +92,15 @@ module ElasticRecord
|
|
92
92
|
clone.facet! facet_or_name, options
|
93
93
|
end
|
94
94
|
|
95
|
+
def aggregate!(aggregation)
|
96
|
+
self.aggregation_values += [aggregation]
|
97
|
+
self
|
98
|
+
end
|
99
|
+
|
100
|
+
def aggregate(aggregation)
|
101
|
+
clone.aggregate! aggregation
|
102
|
+
end
|
103
|
+
|
95
104
|
def order!(*args) # :nodoc:
|
96
105
|
self.order_values += args.flatten
|
97
106
|
self
|
@@ -141,6 +150,7 @@ module ElasticRecord
|
|
141
150
|
build_limit(limit_value),
|
142
151
|
build_offset(offset_value),
|
143
152
|
build_facets(facet_values),
|
153
|
+
build_aggregations(aggregation_values),
|
144
154
|
build_orders(order_values)
|
145
155
|
].compact
|
146
156
|
|
@@ -225,6 +235,10 @@ module ElasticRecord
|
|
225
235
|
end
|
226
236
|
end
|
227
237
|
|
238
|
+
def build_aggregations(aggregations)
|
239
|
+
Arelastic::Searches::Aggregations.new(aggregations) unless aggregations.empty?
|
240
|
+
end
|
241
|
+
|
228
242
|
def build_facets(facets)
|
229
243
|
Arelastic::Searches::Facets.new(facets) unless facets.empty?
|
230
244
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module ElasticRecord
|
2
2
|
class Relation
|
3
|
-
MULTI_VALUE_METHODS = [:extending, :facet, :filter, :order, :select]
|
3
|
+
MULTI_VALUE_METHODS = [:extending, :facet, :filter, :order, :select, :aggregation]
|
4
4
|
SINGLE_VALUE_METHODS = [:query, :limit, :offset, :reverse_order]
|
5
5
|
end
|
6
6
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
class ElasticRecord::ConnectionTest < MiniTest::
|
3
|
+
class ElasticRecord::ConnectionTest < MiniTest::Test
|
4
4
|
def test_servers
|
5
5
|
assert_equal ['foo'], ElasticRecord::Connection.new('foo').servers
|
6
6
|
assert_equal ['foo', 'bar'], ElasticRecord::Connection.new(['foo', 'bar']).servers
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
class ElasticRecord::Index::DocumentsTest < MiniTest::
|
3
|
+
class ElasticRecord::Index::DocumentsTest < MiniTest::Test
|
4
4
|
class InheritedWidget < Widget
|
5
5
|
def self.base_class
|
6
6
|
Widget
|
@@ -41,7 +41,7 @@ class ElasticRecord::Index::DocumentsTest < MiniTest::Unit::TestCase
|
|
41
41
|
index.index_document('bob', name: 'bob')
|
42
42
|
index.index_document('joe', name: 'joe')
|
43
43
|
|
44
|
-
index.delete_by_query(query_string: {query: 'name.analyzed:bob'})
|
44
|
+
index.delete_by_query('query' => {query_string: {query: 'name.analyzed:bob'}})
|
45
45
|
|
46
46
|
refute index.record_exists?('bob')
|
47
47
|
assert index.record_exists?('joe')
|
@@ -64,9 +64,9 @@ class ElasticRecord::Index::DocumentsTest < MiniTest::Unit::TestCase
|
|
64
64
|
index.delete_document '3'
|
65
65
|
|
66
66
|
expected = [
|
67
|
-
{index: {_index:
|
67
|
+
{index: {_index: index.alias_name, _type: "widget", _id: "5"}},
|
68
68
|
{color: "green"},
|
69
|
-
{delete: {_index:
|
69
|
+
{delete: {_index: index.alias_name, _type: "widget", _id: "3"}}
|
70
70
|
]
|
71
71
|
assert_equal expected, index.current_bulk_batch
|
72
72
|
end
|
@@ -89,7 +89,7 @@ class ElasticRecord::Index::DocumentsTest < MiniTest::Unit::TestCase
|
|
89
89
|
InheritedWidget.elastic_index.index_document '5', color: 'green'
|
90
90
|
|
91
91
|
expected = [
|
92
|
-
{index: {_index:
|
92
|
+
{index: {_index: index.alias_name, _type: "widget", _id: "5"}},
|
93
93
|
{color: "green"}
|
94
94
|
]
|
95
95
|
assert_equal expected, index.current_bulk_batch
|
@@ -101,4 +101,4 @@ class ElasticRecord::Index::DocumentsTest < MiniTest::Unit::TestCase
|
|
101
101
|
def index
|
102
102
|
@index ||= Widget.elastic_index
|
103
103
|
end
|
104
|
-
end
|
104
|
+
end
|
@@ -1,13 +1,13 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
class ElasticRecord::Index::ManageTest < MiniTest::
|
3
|
+
class ElasticRecord::Index::ManageTest < MiniTest::Test
|
4
4
|
class Felon
|
5
5
|
include TestModel
|
6
6
|
end
|
7
7
|
|
8
8
|
def setup
|
9
9
|
super
|
10
|
-
Felon.elastic_index.
|
10
|
+
Felon.elastic_index.delete('felons*')
|
11
11
|
end
|
12
12
|
|
13
13
|
def test_create
|
@@ -55,4 +55,4 @@ class ElasticRecord::Index::ManageTest < MiniTest::Unit::TestCase
|
|
55
55
|
def index
|
56
56
|
@index ||= Felon.elastic_index
|
57
57
|
end
|
58
|
-
end
|
58
|
+
end
|
@@ -1,15 +1,13 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
class ElasticRecord::Index::MappingTest < MiniTest::
|
3
|
+
class ElasticRecord::Index::MappingTest < MiniTest::Test
|
4
4
|
def test_delete_mapping
|
5
5
|
index_name = index.create
|
6
|
-
index.get_mapping(index_name)
|
6
|
+
refute_nil index.get_mapping(index_name)['widget']
|
7
7
|
|
8
8
|
index.delete_mapping(index_name)
|
9
9
|
|
10
|
-
|
11
|
-
index.get_mapping(index_name)
|
12
|
-
end
|
10
|
+
assert_nil index.get_mapping(index_name)
|
13
11
|
end
|
14
12
|
|
15
13
|
def test_default_mapping
|
@@ -33,4 +31,4 @@ class ElasticRecord::Index::MappingTest < MiniTest::Unit::TestCase
|
|
33
31
|
def index
|
34
32
|
@index ||= ElasticRecord::Index.new(Widget)
|
35
33
|
end
|
36
|
-
end
|
34
|
+
end
|
@@ -1,13 +1,13 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
class ElasticRecord::Index::PercolatorTest < MiniTest::
|
3
|
+
class ElasticRecord::Index::PercolatorTest < MiniTest::Test
|
4
4
|
def test_create_percolator
|
5
5
|
index.disable_deferring!
|
6
6
|
|
7
7
|
index.delete_percolator('green') if index.percolator_exists?('green')
|
8
8
|
index.delete_percolator('blue') if index.percolator_exists?('blue')
|
9
9
|
|
10
|
-
index.create_percolator('green', 'color' => 'green')
|
10
|
+
index.create_percolator('green', 'query' => {'match' => {'color' => 'green'}})
|
11
11
|
|
12
12
|
assert index.percolator_exists?('green')
|
13
13
|
refute index.percolator_exists?('blue')
|
@@ -16,13 +16,24 @@ class ElasticRecord::Index::PercolatorTest < MiniTest::Unit::TestCase
|
|
16
16
|
def test_delete_percolator
|
17
17
|
index.disable_deferring!
|
18
18
|
|
19
|
-
index.create_percolator('green', 'color' => 'green')
|
19
|
+
index.create_percolator('green', 'query' => {'match' => {'color' => 'green'}})
|
20
20
|
assert index.percolator_exists?('green')
|
21
21
|
|
22
22
|
index.delete_percolator('green')
|
23
23
|
refute index.percolator_exists?('green')
|
24
24
|
end
|
25
25
|
|
26
|
+
def test_reset_percolators
|
27
|
+
index.disable_deferring!
|
28
|
+
|
29
|
+
index.create_percolator('green', 'query' => {'match' => {'color' => 'green'}})
|
30
|
+
assert index.percolator_exists?('green')
|
31
|
+
|
32
|
+
index.reset_percolators
|
33
|
+
|
34
|
+
refute index.percolator_exists?('green')
|
35
|
+
end
|
36
|
+
|
26
37
|
def test_percolate
|
27
38
|
end
|
28
39
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
class ElasticRecord::Index::WarmerTest < MiniTest::
|
3
|
+
class ElasticRecord::Index::WarmerTest < MiniTest::Test
|
4
4
|
def test_create_warmer
|
5
5
|
index.delete_warmer('green') if index.warmer_exists?('green')
|
6
6
|
refute index.warmer_exists?('green')
|
@@ -49,7 +49,7 @@ module ElasticRecord
|
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
|
-
class ElasticRecord::Mysql2Test < MiniTest::
|
52
|
+
class ElasticRecord::Mysql2Test < MiniTest::Test
|
53
53
|
include ElasticRecord::ActiveRecordIntegration
|
54
54
|
|
55
55
|
def setup
|
@@ -64,7 +64,7 @@ class ElasticRecord::Mysql2Test < MiniTest::Unit::TestCase
|
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
|
-
class ElasticRecord::PostgresqlTest < MiniTest::
|
67
|
+
class ElasticRecord::PostgresqlTest < MiniTest::Test
|
68
68
|
include ElasticRecord::ActiveRecordIntegration
|
69
69
|
|
70
70
|
def setup
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
class ElasticRecord::LuceneTest < MiniTest::
|
3
|
+
class ElasticRecord::LuceneTest < MiniTest::Test
|
4
4
|
def test_escape
|
5
5
|
assert_equal "\\\\", ElasticRecord::Lucene.escape("\\")
|
6
6
|
assert_equal "Matt \\&& Joe", ElasticRecord::Lucene.escape("Matt && Joe")
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'helper'
|
2
2
|
require "elastic_record/railties/controller_runtime"
|
3
3
|
|
4
|
-
class ElasticRecord::Railties::ControllerRuntimeTest < MiniTest::
|
4
|
+
class ElasticRecord::Railties::ControllerRuntimeTest < MiniTest::Test
|
5
5
|
class TestRuntime
|
6
6
|
def self.log_process_action(payload)
|
7
7
|
['sweet']
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
class ElasticRecord::Relation::AdminTest < MiniTest::
|
3
|
+
class ElasticRecord::Relation::AdminTest < MiniTest::Test
|
4
4
|
def test_create_percolator
|
5
5
|
index.delete_percolator('green') if index.percolator_exists?('green')
|
6
6
|
|
@@ -25,4 +25,4 @@ class ElasticRecord::Relation::AdminTest < MiniTest::Unit::TestCase
|
|
25
25
|
Widget.elastic_index
|
26
26
|
end
|
27
27
|
|
28
|
-
end
|
28
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
class ElasticRecord::Relation::FinderMethodsTest < MiniTest::
|
3
|
+
class ElasticRecord::Relation::FinderMethodsTest < MiniTest::Test
|
4
4
|
def setup
|
5
5
|
super
|
6
6
|
create_widgets
|
@@ -24,7 +24,7 @@ class ElasticRecord::Relation::FinderMethodsTest < MiniTest::Unit::TestCase
|
|
24
24
|
|
25
25
|
def test_find_passed_an_empty_args
|
26
26
|
assert_raises ActiveRecord::RecordNotFound do
|
27
|
-
Widget.elastic_relation.find
|
27
|
+
Widget.elastic_relation.find
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
@@ -53,6 +53,19 @@ class ElasticRecord::Relation::FinderMethodsTest < MiniTest::Unit::TestCase
|
|
53
53
|
assert_equal 1, Widget.elastic_relation.filter('color' => 'red').all.size
|
54
54
|
end
|
55
55
|
|
56
|
+
def test_find_by
|
57
|
+
Widget.elastic_index.bulk_add [
|
58
|
+
Widget.new(color: 'red', id: '05'),
|
59
|
+
Widget.new(color: 'blue', id: '10'),
|
60
|
+
]
|
61
|
+
|
62
|
+
assert_equal '05', Widget.elastic_relation.find_by(color: 'red').id
|
63
|
+
assert_equal '05', Widget.elastic_relation.find_by!(color: 'red').id
|
64
|
+
assert_raises ActiveRecord::RecordNotFound do
|
65
|
+
Widget.elastic_relation.find_by!(color: 'green')
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
56
69
|
private
|
57
70
|
|
58
71
|
def create_widgets
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
class ElasticRecord::Relation::MergingTest < MiniTest::
|
3
|
+
class ElasticRecord::Relation::MergingTest < MiniTest::Test
|
4
4
|
def test_merge_single_values
|
5
5
|
relation = Widget.elastic_relation.limit(5)
|
6
6
|
other = Widget.elastic_relation.limit(10)
|
@@ -1,14 +1,15 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
class ElasticRecord::Relation::NoneTest < MiniTest::
|
3
|
+
class ElasticRecord::Relation::NoneTest < MiniTest::Test
|
4
4
|
def test_none
|
5
5
|
none = Widget.elastic_relation.none
|
6
6
|
|
7
7
|
assert_equal 0, none.size
|
8
8
|
assert_equal 0, none.count
|
9
9
|
assert_equal [], none.to_a
|
10
|
+
assert_equal({}, none.aggregations)
|
10
11
|
|
11
12
|
expected_elastic = {"not" => {"match_all" => {}}}
|
12
13
|
assert_equal expected_elastic, none.as_elastic
|
13
14
|
end
|
14
|
-
end
|
15
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
class ElasticRecord::Relation::SearchMethodsTest < MiniTest::
|
3
|
+
class ElasticRecord::Relation::SearchMethodsTest < MiniTest::Test
|
4
4
|
def test_query_with_no_queries
|
5
5
|
expected = {"match_all" => {}}
|
6
6
|
|
@@ -57,19 +57,6 @@ class ElasticRecord::Relation::SearchMethodsTest < MiniTest::Unit::TestCase
|
|
57
57
|
assert_equal expected, relation.as_elastic['query']
|
58
58
|
end
|
59
59
|
|
60
|
-
def test_find_by
|
61
|
-
Widget.elastic_index.bulk_add [
|
62
|
-
Widget.new(color: 'red', id: '05'),
|
63
|
-
Widget.new(color: 'blue', id: '10'),
|
64
|
-
]
|
65
|
-
|
66
|
-
assert_equal '05', relation.find_by(color: 'red').id
|
67
|
-
assert_equal '05', relation.find_by!(color: 'red').id
|
68
|
-
assert_raises ActiveRecord::RecordNotFound do
|
69
|
-
relation.find_by!(color: 'green')
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
60
|
def test_query_with_only_query
|
74
61
|
relation.query!('foo')
|
75
62
|
|
@@ -146,6 +133,18 @@ class ElasticRecord::Relation::SearchMethodsTest < MiniTest::Unit::TestCase
|
|
146
133
|
assert_equal expected, faceted.as_elastic['facets']
|
147
134
|
end
|
148
135
|
|
136
|
+
def test_aggregation_with_bang
|
137
|
+
relation.aggregate!("tags" => {"terms" => {"field" => "tags"}})
|
138
|
+
|
139
|
+
expected = {
|
140
|
+
"tags" => {
|
141
|
+
"terms" => {"field" => "tags"}
|
142
|
+
}
|
143
|
+
}
|
144
|
+
|
145
|
+
assert_equal expected, relation.as_elastic['aggs']
|
146
|
+
end
|
147
|
+
|
149
148
|
def test_limit
|
150
149
|
relation.limit!(5)
|
151
150
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
class ElasticRecord::RelationTest < MiniTest::
|
3
|
+
class ElasticRecord::RelationTest < MiniTest::Test
|
4
4
|
def test_count
|
5
5
|
create_widgets [Widget.new(id: 5, color: 'red'), Widget.new(id: 10, color: 'blue')]
|
6
6
|
|
@@ -15,6 +15,15 @@ class ElasticRecord::RelationTest < MiniTest::Unit::TestCase
|
|
15
15
|
assert_equal 2, facets['popular_colors']['total']
|
16
16
|
end
|
17
17
|
|
18
|
+
def test_aggregations
|
19
|
+
create_widgets [Widget.new(id: 5, color: 'red'), Widget.new(id: 10, color: 'blue')]
|
20
|
+
|
21
|
+
aggregations = Widget.elastic_relation.aggregate('popular_colors' => {'terms' => {'field' => 'color'}}).aggregations # Widget.arelastic.facet['popular_colors'].terms('color')).facets
|
22
|
+
|
23
|
+
assert_equal 2, aggregations['popular_colors']['buckets'].size
|
24
|
+
assert_equal %w(red blue).to_set, aggregations['popular_colors']['buckets'].map { |bucket| bucket['key'] }.to_set
|
25
|
+
end
|
26
|
+
|
18
27
|
def test_explain
|
19
28
|
create_widgets [Widget.new(id: 10, color: 'blue')]
|
20
29
|
|
data/test/helper.rb
CHANGED
@@ -13,21 +13,19 @@ ElasticRecord::Config.model_names = %w(Warehouse Widget)
|
|
13
13
|
FakeWeb.allow_net_connect = %r[^https?://127.0.0.1]
|
14
14
|
|
15
15
|
module MiniTest
|
16
|
-
class
|
17
|
-
|
18
|
-
|
19
|
-
FakeWeb.clean_registry
|
16
|
+
class Test
|
17
|
+
def setup
|
18
|
+
FakeWeb.clean_registry
|
20
19
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
end
|
20
|
+
ElasticRecord::Config.models.each do |model|
|
21
|
+
model.elastic_index.create_and_deploy if model.elastic_index.all_names.empty?
|
22
|
+
model.elastic_index.enable_deferring!
|
25
23
|
end
|
24
|
+
end
|
26
25
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
end
|
26
|
+
def teardown
|
27
|
+
ElasticRecord::Config.models.each do |model|
|
28
|
+
model.elastic_index.reset_deferring!
|
31
29
|
end
|
32
30
|
end
|
33
31
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elastic_record
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Infogroup
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-12-
|
12
|
+
date: 2014-12-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: arelastic
|
@@ -17,14 +17,14 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - ">="
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: 0.
|
20
|
+
version: 0.6.0
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - ">="
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version: 0.
|
27
|
+
version: 0.6.0
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: activemodel
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|