elastic_record 0.11.1 → 0.12.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.
Files changed (41) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +2 -1
  3. data/README.rdoc +37 -9
  4. data/elastic_record.gemspec +2 -2
  5. data/lib/elastic_record/callbacks.rb +1 -1
  6. data/lib/elastic_record/connection.rb +36 -13
  7. data/lib/elastic_record/index.rb +33 -4
  8. data/lib/elastic_record/index/configurator.rb +14 -0
  9. data/lib/elastic_record/index/documents.rb +21 -13
  10. data/lib/elastic_record/index/manage.rb +4 -9
  11. data/lib/elastic_record/index/mapping.rb +12 -0
  12. data/lib/elastic_record/index/percolator.rb +1 -0
  13. data/lib/elastic_record/index/settings.rb +4 -0
  14. data/lib/elastic_record/lucene.rb +40 -22
  15. data/lib/elastic_record/model.rb +8 -5
  16. data/lib/elastic_record/relation/batches.rb +8 -1
  17. data/lib/elastic_record/relation/finder_methods.rb +2 -2
  18. data/lib/elastic_record/relation/none.rb +3 -3
  19. data/lib/elastic_record/relation/search_methods.rb +33 -3
  20. data/lib/elastic_record/relation/value_methods.rb +1 -1
  21. data/lib/elastic_record/searches_many.rb +4 -0
  22. data/lib/elastic_record/searches_many/association.rb +25 -14
  23. data/lib/elastic_record/searches_many/reflection.rb +1 -1
  24. data/lib/elastic_record/tasks/index.rake +5 -21
  25. data/test/elastic_record/callbacks_test.rb +9 -0
  26. data/test/elastic_record/connection_test.rb +19 -1
  27. data/test/elastic_record/index/configurator_test.rb +18 -0
  28. data/test/elastic_record/index/documents_test.rb +22 -3
  29. data/test/elastic_record/index/manage_test.rb +7 -0
  30. data/test/elastic_record/index/mapping_test.rb +11 -0
  31. data/test/elastic_record/index/percolator_test.rb +11 -9
  32. data/test/elastic_record/index_test.rb +23 -6
  33. data/test/elastic_record/lucene_test.rb +21 -13
  34. data/test/elastic_record/model_test.rb +9 -9
  35. data/test/elastic_record/relation/batches_test.rb +8 -0
  36. data/test/elastic_record/relation/finder_methods_test.rb +6 -7
  37. data/test/elastic_record/relation/none_test.rb +3 -0
  38. data/test/elastic_record/relation/search_methods_test.rb +17 -41
  39. data/test/elastic_record/relation_test.rb +2 -0
  40. data/test/elastic_record/searches_many/reflection_test.rb +7 -0
  41. metadata +15 -19
@@ -1,23 +1,25 @@
1
1
  require 'helper'
2
2
 
3
3
  class ElasticRecord::Index::PercolatorTest < MiniTest::Spec
4
- def setup
5
- super
6
- index.disable_deferring!
7
- end
8
-
9
4
  def test_create_percolator
10
- index.delete(index.percolator_index_name) if index.exists?(index.percolator_index_name)
5
+ index.delete_percolator('green') if index.percolator_exists?('green')
6
+ index.delete_percolator('blue') if index.percolator_exists?('blue')
11
7
 
12
8
  index.create_percolator('green', 'color' => 'green')
13
9
 
14
- assert index.exists?(index.percolator_index_name)
15
10
  assert index.percolator_exists?('green')
16
11
  refute index.percolator_exists?('blue')
17
12
  end
18
13
 
19
- def test_percolator_index_name
20
- assert_equal 'percolate_widgets', index.percolator_index_name
14
+ def test_delete_percolator
15
+ index.create_percolator('green', 'color' => 'green')
16
+ assert index.percolator_exists?('green')
17
+
18
+ index.delete_percolator('green')
19
+ refute index.percolator_exists?('green')
20
+ end
21
+
22
+ def test_percolate
21
23
  end
22
24
 
23
25
  private
@@ -1,27 +1,44 @@
1
1
  require 'helper'
2
2
 
3
3
  class ElasticRecord::IndexTest < MiniTest::Spec
4
- def test_model_name
5
- index = Widget.elastic_index
4
+ def test_copy
5
+ copied = index.dup
6
+
7
+ refute_equal copied.settings.object_id, index.settings.object_id
8
+ refute_equal copied.mapping.object_id, index.mapping.object_id
9
+ end
6
10
 
11
+ def test_model_name
7
12
  assert_equal 'widgets', index.alias_name
8
13
  assert_equal 'widget', index.type
9
14
  end
10
15
 
11
16
  def test_disable
12
- index = ElasticRecord::Index.new(Widget)
13
-
14
17
  index.disable!
15
18
 
16
19
  assert index.disabled
17
20
  end
18
21
 
19
22
  def test_enable
20
- index = ElasticRecord::Index.new(Widget)
21
-
22
23
  index.disable!
23
24
  index.enable!
24
25
 
25
26
  refute index.disabled
26
27
  end
28
+
29
+ def test_configure
30
+ context = nil
31
+
32
+ index.configure do
33
+ context = self
34
+ end
35
+
36
+ assert_kind_of ElasticRecord::Index::Configurator, context
37
+ end
38
+
39
+ private;
40
+
41
+ def index
42
+ @index ||= ElasticRecord::Index.new(Widget)
43
+ end
27
44
  end
@@ -6,21 +6,29 @@ class ElasticRecord::LuceneTest < MiniTest::Spec
6
6
  assert_equal "Matt \\&& Joe", ElasticRecord::Lucene.escape("Matt && Joe")
7
7
  end
8
8
 
9
- def test_smart_search
10
- assert_smart_escape nil, '', ['name']
11
- assert_smart_escape nil, nil, ['name']
9
+ def test_match_phrase
10
+ assert_match_phrase nil, '', ['name']
11
+ assert_match_phrase nil, nil, ['name']
12
12
 
13
- assert_smart_escape '(name:foo*)', 'foo', ['name']
14
- assert_smart_escape '(name:"foo-bar")', 'foo-bar', ['name']
15
- assert_smart_escape "(name:bob's*)", "bob's", ['name']
16
- assert_smart_escape '(name.analyzed:foo*)', 'foo', ['name'] { |f| "#{f}.analyzed" }
17
- assert_smart_escape '(name:foo* OR street:foo*)', 'foo', ['name', 'street']
18
- assert_smart_escape '(name:"foo bar" OR street:"foo bar") AND (name:faz* OR street:faz*)', '"foo bar" faz', ['name', 'street']
19
- assert_smart_escape '(street:"42 place") AND (name:bar*)', 'street:"42 place" name:bar', ['name', 'street']
13
+ assert_match_phrase '(name:foo*)', 'foo', ['name']
14
+ assert_match_phrase '(name:"foo-bar")', 'foo-bar', ['name']
15
+ assert_match_phrase "(name:bob's*)", "bob's", ['name']
16
+ assert_match_phrase '(name:foo* OR street:foo*)', 'foo', ['name', 'street']
17
+ assert_match_phrase '(name:"foo bar" OR street:"foo bar") AND (name:faz* OR street:faz*)', '"foo bar" faz', ['name', 'street']
18
+ assert_match_phrase '(street:"42 place") AND (name:bar*)', 'street:"42 place" name:bar', ['name', 'street']
19
+ end
20
+
21
+ def test_match_phrase_with_unmatched_quotes
22
+ assert_match_phrase '(name:"foo bar")', '"foo bar', ['name']
23
+ end
24
+
25
+ def test_match_phrase_with_block
26
+ assert_match_phrase '(name.analyzed:foo*)', 'foo', ['name'] { |f| "#{f}.analyzed" }
20
27
  end
21
28
 
22
29
  private
23
- def assert_smart_escape(expected, query, fields, &block)
24
- assert_equal expected, ElasticRecord::Lucene.smart_query(query, fields, &block)
30
+
31
+ def assert_match_phrase(expected, query, fields, &block)
32
+ assert_equal expected, ElasticRecord::Lucene.match_phrase(query, fields, &block)
25
33
  end
26
- end
34
+ end
@@ -4,12 +4,12 @@ class ElasticRecord::ModelTest < MiniTest::Spec
4
4
  class InheritedModel < Widget
5
5
  end
6
6
 
7
- # def test_elastic_connection
8
- # connection = Widget.elastic_connection
9
- #
10
- # assert_equal Widget.elastic_index.type, connection.default_type
11
- # assert_equal Widget.elastic_index.alias_name, connection.default_index
12
- # end
7
+ def test_elastic_connection
8
+ connection = Widget.elastic_connection
9
+
10
+ assert_equal [ElasticRecord::Config.servers], connection.servers
11
+ assert_equal ElasticRecord::Config.connection_options, connection.options
12
+ end
13
13
 
14
14
  def test_elastic_relation
15
15
  relation = Widget.elastic_relation
@@ -24,7 +24,7 @@ class ElasticRecord::ModelTest < MiniTest::Spec
24
24
  assert_equal Widget, index.model
25
25
  end
26
26
 
27
- # def test_elastic_index_inheritence
28
- # refute_equal Widget.elastic_index.object_id, InheritedModel.elastic_index.object_id
29
- # end
27
+ def test_elastic_index_inheritence
28
+ refute_equal Widget.elastic_index.object_id, InheritedModel.elastic_index.object_id
29
+ end
30
30
  end
@@ -14,6 +14,14 @@ class ElasticRecord::Relation::BatchesTest < MiniTest::Spec
14
14
  assert_equal ['5', '10', '15'].to_set, results.to_set
15
15
  end
16
16
 
17
+ def test_ids_in_batches
18
+ results = []
19
+ Widget.elastic_relation.find_ids_in_batches do |widgets|
20
+ results << widgets
21
+ end
22
+ assert_equal [['5', '10', '15'].to_set], results.map(&:to_set)
23
+ end
24
+
17
25
  def test_find_in_batches
18
26
  results = []
19
27
  Widget.elastic_relation.find_in_batches do |widgets|
@@ -21,17 +21,16 @@ class ElasticRecord::Relation::FinderMethodsTest < MiniTest::Spec
21
21
  end
22
22
 
23
23
  def test_first
24
- assert_equal '05', Widget.elastic_relation.first.id
25
- assert_equal '05', Widget.elastic_relation.filter('color' => 'red').first.id
26
- assert_equal '10', Widget.elastic_relation.filter('color' => 'blue').first.id
24
+ assert_equal '10', Widget.elastic_relation.order('color').first.id
25
+ assert_equal '05', Widget.elastic_relation.order('color').filter('color' => 'red').first.id
26
+ assert_equal '10', Widget.elastic_relation.order('color').filter('color' => 'blue').first.id
27
27
  assert_nil Widget.elastic_relation.filter('color' => 'green').first
28
28
  end
29
29
 
30
30
  def test_last
31
- assert_equal '10', Widget.elastic_relation.last.id
32
- assert_equal '05', Widget.elastic_relation.filter('color' => 'red').last.id
33
- assert_equal '10', Widget.elastic_relation.filter('color' => 'blue').last.id
34
- assert_nil Widget.elastic_relation.filter('color' => 'green').last
31
+ assert_equal '05', Widget.elastic_relation.order('color').last.id
32
+ assert_equal '05', Widget.elastic_relation.order('color' => 'asc').last.id
33
+ assert_equal '10', Widget.elastic_relation.order('color' => 'desc').last.id
35
34
  end
36
35
 
37
36
  def test_all
@@ -7,5 +7,8 @@ class ElasticRecord::Relation::NoneTest < MiniTest::Spec
7
7
  assert_equal 0, none.size
8
8
  assert_equal 0, none.count
9
9
  assert_equal [], none.to_a
10
+
11
+ expected_elastic = {"not" => {"match_all" => {}}}
12
+ assert_equal expected_elastic, none.as_elastic
10
13
  end
11
14
  end
@@ -57,41 +57,6 @@ class ElasticRecord::Relation::SearchMethodsTest < MiniTest::Spec
57
57
  assert_equal expected, relation.as_elastic['query']
58
58
  end
59
59
 
60
- def test_filter_with_another_relation
61
- relation.filter! Widget.elastic_search.query('red')
62
-
63
- expected = {
64
- "constant_score" => {
65
- "filter" => {
66
- "has_child" => {
67
- "type" => "widget",
68
- "query" => {
69
- "query_string" => {"query"=>"red"}
70
- }
71
- }
72
- }
73
- }
74
- }
75
-
76
- assert_equal expected, relation.as_elastic['query']
77
- end
78
-
79
- def test_filter_with_nil
80
- relation.filter! 'name' => nil
81
-
82
- expected = {
83
- "constant_score" => {
84
- "filter" => {
85
- "missing" => {
86
- "field" => "name"
87
- }
88
- }
89
- }
90
- }
91
-
92
- assert_equal expected, relation.as_elastic['query']
93
- end
94
-
95
60
  def test_query_with_only_query
96
61
  relation.query!('foo')
97
62
 
@@ -138,7 +103,7 @@ class ElasticRecord::Relation::SearchMethodsTest < MiniTest::Spec
138
103
  assert_equal expected, relation.as_elastic['facets']
139
104
  end
140
105
 
141
- def test_facet_with_string
106
+ def test_facet_bang_with_string
142
107
  relation.facet!('tags', 'size' => 10)
143
108
 
144
109
  expected = {
@@ -153,6 +118,21 @@ class ElasticRecord::Relation::SearchMethodsTest < MiniTest::Spec
153
118
  assert_equal expected, relation.as_elastic['facets']
154
119
  end
155
120
 
121
+ def test_facet_with_string
122
+ faceted = relation.facet('tags', 'size' => 10)
123
+
124
+ expected = {
125
+ "tags" => {
126
+ "terms" => {
127
+ "field" => "tags",
128
+ "size" => 10
129
+ }
130
+ }
131
+ }
132
+
133
+ assert_equal expected, faceted.as_elastic['facets']
134
+ end
135
+
156
136
  def test_limit
157
137
  relation.limit!(5)
158
138
 
@@ -227,12 +207,8 @@ class ElasticRecord::Relation::SearchMethodsTest < MiniTest::Spec
227
207
  assert_equal 'bar', relation.bar
228
208
  end
229
209
 
230
- def test_none
231
- assert_kind_of ElasticRecord::Relation::None, relation.none
232
- end
233
-
234
210
  private
235
211
  def relation
236
212
  @relation ||= Widget.elastic_relation
237
213
  end
238
- end
214
+ end
@@ -16,6 +16,8 @@ class ElasticRecord::RelationTest < MiniTest::Spec
16
16
  end
17
17
 
18
18
  def test_create_percolator
19
+ Widget.elastic_index.reset_percolator
20
+
19
21
  Widget.elastic_relation.filter(color: 'green').create_percolator('green')
20
22
  Widget.elastic_relation.filter(color: 'blue').create_percolator('blue')
21
23
  widget = Widget.new(color: 'green')
@@ -1,6 +1,11 @@
1
1
  require 'helper'
2
2
 
3
3
  class ElasticRecord::SearchesMany::ReflectionTest < MiniTest::Spec
4
+ def test_klass_name
5
+ assert_equal 'Product', reflection_class.new(Warehouse, :widgets, {class_name: 'Product'}).klass_name
6
+ assert_equal 'Widget', reflection_class.new(Warehouse, :widgets, {}).klass_name
7
+ end
8
+
4
9
  def test_touch_column
5
10
  assert_nil reflection_class.new(Warehouse, :widgets, {}).touch_column
6
11
  assert_equal :updated_at, reflection_class.new(Warehouse, :widgets, touch: true).touch_column
@@ -14,7 +19,9 @@ class ElasticRecord::SearchesMany::ReflectionTest < MiniTest::Spec
14
19
  end
15
20
 
16
21
  private
22
+
17
23
  def reflection_class
18
24
  ElasticRecord::SearchesMany::Reflection
19
25
  end
26
+
20
27
  end
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elastic_record
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.1
5
- prerelease:
4
+ version: 0.12.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Infogroup
@@ -10,40 +9,36 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2012-12-19 00:00:00.000000000 Z
12
+ date: 2013-04-09 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: arelastic
17
- prerelease: false
18
16
  requirement: !ruby/object:Gem::Requirement
19
17
  requirements:
20
- - - ! '>='
18
+ - - '>='
21
19
  - !ruby/object:Gem::Version
22
20
  version: '0'
23
- none: false
24
21
  type: :runtime
22
+ prerelease: false
25
23
  version_requirements: !ruby/object:Gem::Requirement
26
24
  requirements:
27
- - - ! '>='
25
+ - - '>='
28
26
  - !ruby/object:Gem::Version
29
27
  version: '0'
30
- none: false
31
28
  - !ruby/object:Gem::Dependency
32
29
  name: activemodel
33
- prerelease: false
34
30
  requirement: !ruby/object:Gem::Requirement
35
31
  requirements:
36
- - - ! '>='
32
+ - - '>='
37
33
  - !ruby/object:Gem::Version
38
34
  version: '0'
39
- none: false
40
35
  type: :runtime
36
+ prerelease: false
41
37
  version_requirements: !ruby/object:Gem::Requirement
42
38
  requirements:
43
- - - ! '>='
39
+ - - '>='
44
40
  - !ruby/object:Gem::Version
45
41
  version: '0'
46
- none: false
47
42
  description: Find your records with elastic search
48
43
  email: developer@matthewhiggins.com
49
44
  executables: []
@@ -63,6 +58,7 @@ files:
63
58
  - lib/elastic_record/config.rb
64
59
  - lib/elastic_record/connection.rb
65
60
  - lib/elastic_record/index.rb
61
+ - lib/elastic_record/index/configurator.rb
66
62
  - lib/elastic_record/index/deferred.rb
67
63
  - lib/elastic_record/index/documents.rb
68
64
  - lib/elastic_record/index/manage.rb
@@ -94,6 +90,7 @@ files:
94
90
  - test/elastic_record/callbacks_test.rb
95
91
  - test/elastic_record/config_test.rb
96
92
  - test/elastic_record/connection_test.rb
93
+ - test/elastic_record/index/configurator_test.rb
97
94
  - test/elastic_record/index/documents_test.rb
98
95
  - test/elastic_record/index/manage_test.rb
99
96
  - test/elastic_record/index/mapping_test.rb
@@ -124,26 +121,25 @@ files:
124
121
  homepage: http://github.com/data-axle/elastic_record
125
122
  licenses:
126
123
  - MIT
124
+ metadata: {}
127
125
  post_install_message:
128
126
  rdoc_options: []
129
127
  require_paths:
130
128
  - lib
131
129
  required_ruby_version: !ruby/object:Gem::Requirement
132
130
  requirements:
133
- - - ! '>='
131
+ - - '>='
134
132
  - !ruby/object:Gem::Version
135
133
  version: 1.9.3
136
- none: false
137
134
  required_rubygems_version: !ruby/object:Gem::Requirement
138
135
  requirements:
139
- - - ! '>='
136
+ - - '>='
140
137
  - !ruby/object:Gem::Version
141
138
  version: 1.8.11
142
- none: false
143
139
  requirements: []
144
140
  rubyforge_project:
145
- rubygems_version: 1.8.24
141
+ rubygems_version: 2.0.0
146
142
  signing_key:
147
- specification_version: 3
143
+ specification_version: 4
148
144
  summary: Use Elastic Search with your objects
149
145
  test_files: []