goodyear 0.2.1 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/goodyear.rb +1 -0
- data/lib/goodyear/enumerable.rb +2 -2
- data/lib/goodyear/query_methods.rb +1 -0
- data/lib/goodyear/scan.rb +115 -0
- data/lib/goodyear/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24a3446eba1db314be332ef46c9328fe02904e9a
|
4
|
+
data.tar.gz: 2d1c99af47a5ce7bcc849b683c6c13a1e5580b3e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e0a27c7887ca6637debf48443819388f80f43e347f456d2407db696b8e04c297315a9ac9b2ed89dad5089e94c220c633a67ef50cb6eed65eff280aafcd0a0fb
|
7
|
+
data.tar.gz: 0ce8d59b1b3b405859929b00bf5b4fc74b9668849606cbc05277d41188d80d216ec272182d575e67e6d2ddb38b3ce6adb70f370315b40f23f6e6549f78fe9d3e
|
data/lib/goodyear.rb
CHANGED
data/lib/goodyear/enumerable.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Goodyear
|
2
2
|
module Enumerable
|
3
3
|
def each &block
|
4
|
-
|
4
|
+
results.each do |result|
|
5
5
|
if block_given?
|
6
6
|
block.call result
|
7
7
|
else
|
@@ -11,7 +11,7 @@ module Goodyear
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def collect &block
|
14
|
-
|
14
|
+
results.collect do |result|
|
15
15
|
if block_given?
|
16
16
|
block.call result
|
17
17
|
else
|
@@ -0,0 +1,115 @@
|
|
1
|
+
module Tire
|
2
|
+
module Search
|
3
|
+
|
4
|
+
|
5
|
+
# Performs a "scan/scroll" search request, which obtains a `scroll_id`
|
6
|
+
# and keeps returning documents matching the passed query (or all documents) in batches.
|
7
|
+
#
|
8
|
+
# You may want to iterate over the batches being returned:
|
9
|
+
#
|
10
|
+
# search = Tire::Search::Scan.new('articles')
|
11
|
+
# search.each do |results|
|
12
|
+
# puts results.map(&:title)
|
13
|
+
# end
|
14
|
+
#
|
15
|
+
# The scan object has a fully Enumerable-compatible interface, so you may
|
16
|
+
# call methods like `map` or `each_with_index` on it.
|
17
|
+
#
|
18
|
+
# To iterate over individual documents, use the `each_document` method:
|
19
|
+
#
|
20
|
+
# search.each_document do |document|
|
21
|
+
# puts document.title
|
22
|
+
# end
|
23
|
+
#
|
24
|
+
# You may limit the result set being returned by a regular Tire DSL query
|
25
|
+
# (or a hash, if you prefer), passed as a second argument:
|
26
|
+
#
|
27
|
+
# search = Tire::Search::Scan.new('articles') do
|
28
|
+
# query { term 'author.exact', 'John Smith' }
|
29
|
+
# end
|
30
|
+
#
|
31
|
+
# The feature is also exposed in the Tire top-level DSL:
|
32
|
+
#
|
33
|
+
# search = Tire.scan 'articles' do
|
34
|
+
# query { term 'author.exact', 'John Smith' }
|
35
|
+
# end
|
36
|
+
#
|
37
|
+
# See Elasticsearch documentation for further reference:
|
38
|
+
#
|
39
|
+
# * http://www.elasticsearch.org/guide/reference/api/search/search-type.html
|
40
|
+
# * http://www.elasticsearch.org/guide/reference/api/search/scroll.html
|
41
|
+
#
|
42
|
+
class Scan
|
43
|
+
include Enumerable
|
44
|
+
|
45
|
+
attr_reader :indices, :options, :search
|
46
|
+
|
47
|
+
def initialize(indices=nil, options={}, &block)
|
48
|
+
@indices = Array(indices)
|
49
|
+
@options = options.update(:search_type => 'scan', :scroll => '10m')
|
50
|
+
@seen = 0
|
51
|
+
@tire_options = options.delete(:tire) || {}
|
52
|
+
@search = Search.new(@indices, @options.merge(@tire_options), &block)
|
53
|
+
end
|
54
|
+
|
55
|
+
def url; Configuration.url + "/_search/scroll"; end
|
56
|
+
def params; @options.empty? ? '' : '?' + @options.to_param; end
|
57
|
+
def results; @results || (__perform; @results); end
|
58
|
+
def response; @response || (__perform; @response); end
|
59
|
+
def json; @json || (__perform; @json); end
|
60
|
+
def total; @total || (__perform; @total); end
|
61
|
+
def seen; @seen || (__perform; @seen); end
|
62
|
+
|
63
|
+
def scroll_id
|
64
|
+
@scroll_id ||= @search.perform.json['_scroll_id']
|
65
|
+
end
|
66
|
+
|
67
|
+
def each
|
68
|
+
until results.empty?
|
69
|
+
yield results.results
|
70
|
+
__perform
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def each_document
|
75
|
+
until results.empty?
|
76
|
+
results.each { |item| yield item }
|
77
|
+
__perform
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def size
|
82
|
+
results.size
|
83
|
+
end
|
84
|
+
|
85
|
+
def __perform
|
86
|
+
@response = Configuration.client.get [url, params].join, scroll_id
|
87
|
+
@json = MultiJson.decode @response.body
|
88
|
+
@results = Results::Collection.new @json, @options
|
89
|
+
@total = @json['hits']['total'].to_i
|
90
|
+
@seen += @results.size
|
91
|
+
@scroll_id = @json['_scroll_id']
|
92
|
+
return self
|
93
|
+
ensure
|
94
|
+
__logged
|
95
|
+
end
|
96
|
+
|
97
|
+
def to_a; results; end; alias :to_ary :to_a
|
98
|
+
def to_curl; %Q|curl -X GET '#{url}?pretty' -d '#{@scroll_id}'|; end
|
99
|
+
|
100
|
+
def __logged(error=nil)
|
101
|
+
if Configuration.logger
|
102
|
+
Configuration.logger.log_request 'scroll', nil, to_curl
|
103
|
+
|
104
|
+
took = @json['took'] rescue nil
|
105
|
+
code = @response.code rescue nil
|
106
|
+
body = "#{@seen}/#{@total} (#{@seen/@total.to_f*100}%)" rescue nil
|
107
|
+
|
108
|
+
Configuration.logger.log_response code || 'N/A', took || 'N/A', body
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
end
|
data/lib/goodyear/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: goodyear
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Spencer Markowski
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-03-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -64,6 +64,7 @@ files:
|
|
64
64
|
- lib/goodyear/query_cache.rb
|
65
65
|
- lib/goodyear/query_methods.rb
|
66
66
|
- lib/goodyear/railtie.rb
|
67
|
+
- lib/goodyear/scan.rb
|
67
68
|
- lib/goodyear/version.rb
|
68
69
|
homepage: https://github.com/theablefew/goodyear
|
69
70
|
licenses:
|