elastic_record 1.2.2 → 1.2.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6d254216fe907d0c00ffb1c00aeb7ef1fcd1c034
4
- data.tar.gz: 99b0c21ca7295348e69a666d6a3981cb49b497c1
3
+ metadata.gz: 01876488cf87aafffd46c830a6712dd84f56c83d
4
+ data.tar.gz: 7db2399fa5d44bf81a3c157cd23c95d60b040c19
5
5
  SHA512:
6
- metadata.gz: f4728a0563f5fddc5a127d164ae816d3e8c7d037d4490b43a3744d8e0bf3174e08ac040340406cc201095728b1e82f02c45431b24191c9e810469fe69a37961b
7
- data.tar.gz: 7b007f7549f9159f3d6deedca8c25f2f8e7edf31e70b85f3eeae3fb75bf79513e1769c5019c4e0d17ffcad493d8991947b4ab926a9014c31c839789148e2eac6
6
+ metadata.gz: 4f8a6c431823345a68a2da9d2d6c6099f5449a240068c60aa1f3f6ccbd8d2d74bb95ef3ed2f4c6c4882c0a65c537b298adc0b42b7ecc979b04b82e6cf708181e
7
+ data.tar.gz: 032af52b81c1e79b7957934aa1812f809ef8109f18c418d95fd42dcfa70e99472dd28825b62020714d00aad35cc5f5945f95c7923e300d5e982db8c68c7298cc
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'elastic_record'
5
- s.version = '1.2.2'
5
+ s.version = '1.2.3'
6
6
  s.summary = 'Use Elastic Search with your objects'
7
7
  s.description = 'Find your records with elastic search'
8
8
 
@@ -1,5 +1,28 @@
1
1
  module ElasticRecord
2
2
  class Relation
3
+ class ScanSearch
4
+ attr_reader :scroll_id
5
+
6
+ def initialize(model, scroll_id, options = {})
7
+ @model = model
8
+ @scroll_id = scroll_id
9
+ @options = options
10
+ end
11
+
12
+ def request_more_ids
13
+ json = @model.elastic_index.scroll(@scroll_id, keep_alive)
14
+ json['hits']['hits'].map { |hit| hit['_id'] }
15
+ end
16
+
17
+ def keep_alive
18
+ @options[:keep_alive] || (raise "Must provide a :keep_alive option")
19
+ end
20
+
21
+ def requested_batch_size
22
+ @options[:batch_size]
23
+ end
24
+ end
25
+
3
26
  module Batches
4
27
  def find_each(options = {})
5
28
  find_in_batches(options) do |records|
@@ -14,24 +37,10 @@ module ElasticRecord
14
37
  end
15
38
 
16
39
  def find_ids_in_batches(options = {}, &block)
17
- options.assert_valid_keys(:batch_size, :keep_alive)
18
-
19
- scroll_keep_alive = options[:keep_alive] || ElasticRecord::Config.scroll_keep_alive
20
- size = options[:batch_size] || 100
21
-
22
- options = {
23
- scroll: scroll_keep_alive,
24
- size: size,
25
- search_type: 'scan'
26
- }.update(options)
40
+ scan_search = create_scan_search(options)
27
41
 
28
- search_result = klass.elastic_index.search(as_elastic, options)
29
- scroll_id = search_result['_scroll_id']
30
- hit_count = 0
31
-
32
- while (hit_ids = get_scroll_hit_ids(scroll_id, scroll_keep_alive)).any?
33
- hit_count += hit_ids.size
34
- hit_ids.each_slice(size, &block)
42
+ while (hit_ids = scan_search.request_more_ids).any?
43
+ hit_ids.each_slice(scan_search.requested_batch_size, &block)
35
44
  end
36
45
  end
37
46
 
@@ -41,12 +50,15 @@ module ElasticRecord
41
50
  end
42
51
  end
43
52
 
44
- private
53
+ def create_scan_search(options = {})
54
+ options[:batch_size] ||= 100
55
+ options[:keep_alive] ||= ElasticRecord::Config.scroll_keep_alive
45
56
 
46
- def get_scroll_hit_ids(scroll_id, scroll_keep_alive)
47
- json = klass.elastic_index.scroll(scroll_id, scroll_keep_alive)
48
- json['hits']['hits'].map { |hit| hit['_id'] }
49
- end
57
+ search_options = {search_type: 'scan', size: options[:batch_size], scroll: options[:keep_alive]}
58
+ json = klass.elastic_index.search(as_elastic, search_options)
59
+
60
+ ElasticRecord::Relation::ScanSearch.new(klass, json['_scroll_id'], options)
61
+ end
50
62
  end
51
63
  end
52
64
  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.2.2
4
+ version: 1.2.3
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-04-17 00:00:00.000000000 Z
12
+ date: 2014-05-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: arelastic