elastic_record 1.1.5 → 1.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0f00def1bf454a01cf7db164569a256fa3872f12
4
- data.tar.gz: 3674835adb8a4d2b803f8b00b1f71e9239e3cf15
3
+ metadata.gz: 4f4401dda11a00875bd98fb93aa20968e6026db3
4
+ data.tar.gz: 0d1ec26e07c6138e08c1d6037a2f7a201e391031
5
5
  SHA512:
6
- metadata.gz: cbe0b1f75dc593b47372e0b4d8da74398747dfd87c520e3286baf459e349f8665a6c9863111b3c3415da749c97f1a503a66356a58104cda647008dfd5351ccd2
7
- data.tar.gz: a5d239eab2b96cab5aa461bd06671d6e46f7c22ff85ba688b7e0a5e22b4688c385446ba37af750e1b3476488f0028fd2d4da90b034afda842b35e8cfb053ebe4
6
+ metadata.gz: d62018904effb980ea3b52f3de380324b37a559ad53eba9b833d1849d59fc35e9918a950f1d5a9eb519086ed3e59dcf1cd52beaa76739a88ce3cfae5536cbe26
7
+ data.tar.gz: 6d0860961a41249853a96366c8fcafef952c5ac367df43c09a59623e587d14837503f33628e43dff2925a0ae97bf98980a6a97a036c7518874ce41fda17fd456
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'elastic_record'
5
- s.version = '1.1.5'
5
+ s.version = '1.1.6'
6
6
  s.summary = 'Use Elastic Search with your objects'
7
7
  s.description = 'Find your records with elastic search'
8
8
 
@@ -15,15 +15,5 @@ module ElasticRecord
15
15
  include ElasticRecord::Railties::ControllerRuntime
16
16
  end
17
17
  end
18
-
19
- initializer "elastic_record.orm" do |app|
20
- ActiveSupport.on_load(:active_record) do
21
- require 'elastic_record/integration/active_record'
22
- end
23
-
24
- ActiveSupport.on_load(:cassandra_object) do
25
- require 'elastic_record/integration/cassandra_object'
26
- end
27
- end
28
18
  end
29
19
  end
@@ -41,8 +41,7 @@ module ElasticRecord
41
41
 
42
42
  def to_a
43
43
  @records ||= begin
44
- scope = select_values.any? ? klass.select(select_values) : klass
45
- records = scope.load_elastic_record_hits(to_ids)
44
+ records = load_hits(to_ids)
46
45
  eager_load_associations(records) if eager_loading?
47
46
  records
48
47
  end
@@ -81,6 +80,14 @@ module ElasticRecord
81
80
  @search_results ||= klass.elastic_index.search(as_elastic)
82
81
  end
83
82
 
83
+ def load_hits(ids)
84
+ scope = select_values.any? ? klass.select(select_values) : klass
85
+ if defined?(ActiveRecord::Base) && klass < ActiveRecord::Base
86
+ scope = scope.order("FIELD(#{connection.quote_column_name(primary_key)}, #{ids.join(',')})")
87
+ end
88
+ scope.find(ids)
89
+ end
90
+
84
91
  def eager_load_associations(records)
85
92
  records = records.reject(&:marked_for_destruction?)
86
93
  ids = records.map(&:id)
@@ -19,9 +19,9 @@ ActiveSupport.on_load :active_record do
19
19
  end
20
20
  end
21
21
 
22
- require 'elastic_record/integration/active_record'
23
22
  class Project < ActiveRecord::Base
24
23
  include ElasticRecord::Model
24
+ include ElasticRecord::Callbacks
25
25
 
26
26
  self.elastic_index.mapping[:properties].update(
27
27
  name: { type: 'string', index: 'not_analyzed' }
@@ -29,11 +29,17 @@ class Project < ActiveRecord::Base
29
29
  end
30
30
 
31
31
  class ElasticRecord::ActiveRecordTest < MiniTest::Unit::TestCase
32
- def test_load_elastic_record_hits
32
+ def setup
33
+ super
34
+ Project.elastic_index.create_and_deploy if Project.elastic_index.all_names.empty?
35
+ end
36
+
37
+ def test_ordering
33
38
  poo_product = Project.create! name: "Poo"
34
39
  bear_product = Project.create! name: "Bear"
40
+ Project.elastic_index.refresh
35
41
 
36
- assert_equal [poo_product, bear_product], Project.load_elastic_record_hits([poo_product.id, bear_product.id])
37
- assert_equal [bear_product, poo_product], Project.load_elastic_record_hits([bear_product.id, poo_product.id])
42
+ assert_equal [bear_product, poo_product], Project.elastic_relation.order(name: 'asc')
43
+ assert_equal [poo_product, bear_product], Project.elastic_relation.order(name: 'desc')
38
44
  end
39
45
  end
data/test/helper.rb CHANGED
@@ -24,9 +24,8 @@ module MiniTest
24
24
 
25
25
  FakeWeb.clean_registry
26
26
 
27
- Widget.elastic_index.create_and_deploy if Widget.elastic_index.all_names.empty?
28
-
29
27
  ElasticRecord::Config.models.each do |model|
28
+ model.elastic_index.create_and_deploy if model.elastic_index.all_names.empty?
30
29
  model.elastic_index.enable_deferring!
31
30
  end
32
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: 1.1.5
4
+ version: 1.1.6
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: 2013-09-20 00:00:00.000000000 Z
12
+ date: 2013-10-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: arelastic
@@ -67,8 +67,6 @@ files:
67
67
  - lib/elastic_record/index/percolator.rb
68
68
  - lib/elastic_record/index/settings.rb
69
69
  - lib/elastic_record/index/warmer.rb
70
- - lib/elastic_record/integration/active_record.rb
71
- - lib/elastic_record/integration/cassandra_object.rb
72
70
  - lib/elastic_record/log_subscriber.rb
73
71
  - lib/elastic_record/lucene.rb
74
72
  - lib/elastic_record/model.rb
@@ -1,7 +0,0 @@
1
- module ActiveRecord
2
- class Base
3
- def self.load_elastic_record_hits(ids)
4
- order("FIELD(#{connection.quote_column_name(primary_key)}, #{ids.join(',')})").find(ids)
5
- end
6
- end
7
- end
@@ -1,7 +0,0 @@
1
- module CassandraObject
2
- class Base
3
- def self.load_elastic_record_hits(ids)
4
- find(ids)
5
- end
6
- end
7
- end