es-elasticity 0.3.8 → 0.3.9

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: d2d89f25600a3ab77988c2d38f35096a69b888b9
4
- data.tar.gz: e2af05a59820f1b59a39ead2909254ebf7592f13
3
+ metadata.gz: 0b43991880f2556f0dfaa3e6a0a641fe21f39816
4
+ data.tar.gz: 25afec66923b407330c648fb767d9405cc1ec3cd
5
5
  SHA512:
6
- metadata.gz: 87a385b5dcbb63c72e820c37d8f606db5b2183bbca693461153999e5330d910e62cbfa3dcb722b290484d931859da4cebfb703ca426c0f5d8452ee0ffd3066ff
7
- data.tar.gz: 077bc0215ff326b4a684dab6a3b556722128fe915b9999089f4842d57e656c64d90b5f5aee534123f86484cce4c115dfe8ac6e9614c9e911b2cc4005d930390a
6
+ metadata.gz: ba981a87ef6b156d589c9f8c60505998a77b5cd6827c70af2f34719aa15c3306904288f9715713536d18570258c34b4332271bb7b11a3cd2eaae193fec58ba82
7
+ data.tar.gz: 0a6dabe8a4d45f85928e1bd5531a6d29dbc625115652a6029abe395f7506341458b40f14327cd166322f5d657b538549edb1859ab1eab42da8ce516074782b42
@@ -76,6 +76,8 @@ module Elasticity
76
76
 
77
77
  attr_accessor :search_definition
78
78
 
79
+ DEFAULT_SIZE = 10
80
+
79
81
  def initialize(client, search_definition, &mapper)
80
82
  @client = client
81
83
  @search_definition = search_definition
@@ -118,6 +120,22 @@ module Elasticity
118
120
  end
119
121
  end
120
122
 
123
+ # for pagination
124
+ def per_page
125
+ @search_definition.body[:size] || DEFAULT_SIZE
126
+ end
127
+
128
+ # for pagination
129
+ def total_pages
130
+ (total.to_f / per_page.to_f).ceil
131
+ end
132
+
133
+ # for pagination
134
+ def current_page
135
+ return 1 if @search_definition.body[:from].nil?
136
+ @search_definition.body[:from] / per_page + 1
137
+ end
138
+
121
139
  private
122
140
 
123
141
  def response
@@ -1,3 +1,3 @@
1
1
  module Elasticity
2
- VERSION = "0.3.8"
2
+ VERSION = "0.3.9"
3
3
  end
@@ -140,6 +140,40 @@ RSpec.describe "Search" do
140
140
  end
141
141
  end
142
142
 
143
+ describe Elasticity::Search::LazySearch do
144
+ it "provides defaul properties for pagination" do
145
+ subject = Elasticity::Search::Facade.new(client, Elasticity::Search::Definition.new(index_name, document_type, body))
146
+ expect(client).to receive(:search).with(index: index_name, type: document_type, body: body).and_return(full_response)
147
+ docs = subject.documents(klass)
148
+
149
+ expect(docs.per_page).to eq(10)
150
+ expect(docs.total_pages).to eq(1)
151
+ expect(docs.current_page).to eq(1)
152
+ end
153
+
154
+ it "provides custom properties for pagination" do
155
+ subject = Elasticity::Search::Facade.new(
156
+ client,
157
+ Elasticity::Search::Definition.new(
158
+ index_name,
159
+ document_type,
160
+ { size: 14, from: 25, filter: {} }
161
+ )
162
+ )
163
+ expect(client).to receive(:search).
164
+ with(
165
+ index: index_name,
166
+ type: document_type,
167
+ body: { size: 14, from: 25, filter: {} }
168
+ ).and_return({ "hits" => { "total" => 112 } })
169
+ docs = subject.documents(klass)
170
+
171
+ expect(docs.per_page).to eq(14)
172
+ expect(docs.total_pages).to eq(8)
173
+ expect(docs.current_page).to eq(2)
174
+ end
175
+ end
176
+
143
177
  describe Elasticity::Search::DocumentProxy do
144
178
  let :search do
145
179
  Elasticity::Search::Facade.new(client, Elasticity::Search::Definition.new(index_name, "document", body))
metadata CHANGED
@@ -1,167 +1,167 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: es-elasticity
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.8
4
+ version: 0.3.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rodrigo Kochenburger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-18 00:00:00.000000000 Z
11
+ date: 2015-09-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.7'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.7'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ~>
32
32
  - !ruby/object:Gem::Version
33
33
  version: '10.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ~>
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ~>
46
46
  - !ruby/object:Gem::Version
47
47
  version: 3.1.0
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ~>
53
53
  - !ruby/object:Gem::Version
54
54
  version: 3.1.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: simplecov
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ~>
60
60
  - !ruby/object:Gem::Version
61
61
  version: 0.7.1
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ~>
67
67
  - !ruby/object:Gem::Version
68
68
  version: 0.7.1
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: oj
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - '>='
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - '>='
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: pry
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ">="
87
+ - - '>='
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ">="
94
+ - - '>='
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: codeclimate-test-reporter
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ">="
101
+ - - '>='
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ">="
108
+ - - '>='
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: redis
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - ">="
115
+ - - '>='
116
116
  - !ruby/object:Gem::Version
117
117
  version: '0'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - ">="
122
+ - - '>='
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: activesupport
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - "~>"
129
+ - - ~>
130
130
  - !ruby/object:Gem::Version
131
131
  version: '4.0'
132
132
  type: :runtime
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - "~>"
136
+ - - ~>
137
137
  - !ruby/object:Gem::Version
138
138
  version: '4.0'
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: activemodel
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
- - - "~>"
143
+ - - ~>
144
144
  - !ruby/object:Gem::Version
145
145
  version: '4.0'
146
146
  type: :runtime
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
- - - "~>"
150
+ - - ~>
151
151
  - !ruby/object:Gem::Version
152
152
  version: '4.0'
153
153
  - !ruby/object:Gem::Dependency
154
154
  name: elasticsearch
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
- - - "~>"
157
+ - - ~>
158
158
  - !ruby/object:Gem::Version
159
159
  version: 1.0.12
160
160
  type: :runtime
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
- - - "~>"
164
+ - - ~>
165
165
  - !ruby/object:Gem::Version
166
166
  version: 1.0.12
167
167
  description: Elasticity provides a higher level abstraction on top of [elasticsearch-ruby](https://github.com/elasticsearch/elasticsearch-ruby)
@@ -172,10 +172,10 @@ executables: []
172
172
  extensions: []
173
173
  extra_rdoc_files: []
174
174
  files:
175
- - ".gitignore"
176
- - ".rspec"
177
- - ".simplecov"
178
- - ".travis.yml"
175
+ - .gitignore
176
+ - .rspec
177
+ - .simplecov
178
+ - .travis.yml
179
179
  - Gemfile
180
180
  - LICENSE.txt
181
181
  - README.md
@@ -212,17 +212,17 @@ require_paths:
212
212
  - lib
213
213
  required_ruby_version: !ruby/object:Gem::Requirement
214
214
  requirements:
215
- - - ">="
215
+ - - '>='
216
216
  - !ruby/object:Gem::Version
217
217
  version: '0'
218
218
  required_rubygems_version: !ruby/object:Gem::Requirement
219
219
  requirements:
220
- - - ">="
220
+ - - '>='
221
221
  - !ruby/object:Gem::Version
222
222
  version: '0'
223
223
  requirements: []
224
224
  rubyforge_project:
225
- rubygems_version: 2.4.5
225
+ rubygems_version: 2.0.0
226
226
  signing_key:
227
227
  specification_version: 4
228
228
  summary: ActiveModel-based library for working with Elasticsearch