es-elasticity 0.6.2 → 0.6.3

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: 8fb560ae15568a614d3ee458f20feefdd5a2ac59
4
- data.tar.gz: f19e9eaa49475de62ad69068b4fc210028520f32
3
+ metadata.gz: db223045f4a1f6c4550940c3a6a8ab31313e2641
4
+ data.tar.gz: 05c9d8c099afe031a5c603c0cd4ab54e1b8d6fb7
5
5
  SHA512:
6
- metadata.gz: 78932ec63a5a18de6ddf9d94ce9f2f46af3e765f465a2078188e5e232d8c2b6dc67e11ea61c0b6f9dd1da7daed8b9bed3f1c051505cc432a4e9373b6289e9067
7
- data.tar.gz: 46d3412bec0201ff96e4ff6106988da16c92e45c06a016506dbb5e5b73c173c84ec479386af2acf9c2941f0b795e8727391a75d90eaeae788ab6198dde0a6a6f
6
+ metadata.gz: 7722a0f30843c9236e8ed33eabd4ebeafe1bcd5ec04e4bfcfc74ff6c9cf6a1133b39ff5b45e603e8e6475e0b31fee082591d231ffff9e1b7aa2ee18bbe22306e
7
+ data.tar.gz: 05a92b3f0a31bcb87b758bd57c1cdaba037b57d36a0e97502db6b9072cb1c0712abde819d5d0fbac9a778b10eb2dbd2bc653e844d06fed37d8d4d390fcb78302
data/README.md CHANGED
@@ -134,7 +134,7 @@ Search::User.bulk_index(users)
134
134
  If you you'd like to update a single attribute of the document instead of updating the entire document, you can use the `bulk_update` api.
135
135
 
136
136
  ```ruby
137
- document = [
137
+ documents = [
138
138
  { _id: 1, attr_name: "attr_name", attr_vale: "attr_value" },
139
139
  { _id: 2, attr_name: "attr_name", attr_vale: "attr_value" }
140
140
  ]
@@ -85,7 +85,7 @@ module Elasticity
85
85
  include Enumerable
86
86
 
87
87
  delegate :each, :size, :length, :[], :+, :-, :&, :|, :total, :per_page,
88
- :total_pages, :current_page, :aggregations, to: :search_results
88
+ :total_pages, :current_page, :next_page, :previous_page, :aggregations, to: :search_results
89
89
 
90
90
  attr_accessor :search_definition
91
91
 
@@ -196,7 +196,8 @@ module Elasticity
196
196
 
197
197
  class Relation < ActiveSupport::ProxyObject
198
198
 
199
- delegate :total, :per_page, :total_pages, :current_page, :aggregations, to: :@results
199
+ delegate :total, :per_page, :total_pages, :current_page, :next_page,
200
+ :previous_page, :aggregations, to: :@results
200
201
 
201
202
  def initialize(relation, search_definition, response)
202
203
  @relation = relation
@@ -300,29 +301,38 @@ module Elasticity
300
301
  @documents.each(&block)
301
302
  end
302
303
 
303
- def total
304
- @response["hits"]["total"]
305
- end
306
-
307
304
  def aggregations
308
305
  @response["aggregations"] ||= {}
309
306
  end
310
307
 
311
- # for pagination
312
- def per_page
313
- @body[:size] || DEFAULT_SIZE
308
+ def total
309
+ @response["hits"]["total"]
314
310
  end
311
+ alias_method :total_entries, :total
315
312
 
316
313
  # for pagination
317
314
  def total_pages
318
315
  (total.to_f / per_page.to_f).ceil
319
316
  end
320
317
 
318
+ # for pagination
319
+ def per_page
320
+ @body[:size] || DEFAULT_SIZE
321
+ end
322
+
321
323
  # for pagination
322
324
  def current_page
323
325
  return 1 if @body[:from].nil?
324
326
  @body[:from] / per_page + 1
325
327
  end
328
+
329
+ def next_page
330
+ current_page < total_pages ? (current_page + 1) : nil
331
+ end
332
+
333
+ def previous_page
334
+ current_page > 1 ? (current_page - 1) : nil
335
+ end
326
336
  end
327
337
  end
328
338
  end
@@ -1,3 +1,3 @@
1
1
  module Elasticity
2
- VERSION = "0.6.2"
2
+ VERSION = "0.6.3"
3
3
  end
@@ -152,6 +152,8 @@ RSpec.describe "Search" do
152
152
  expect(docs.per_page).to eq(10)
153
153
  expect(docs.total_pages).to eq(1)
154
154
  expect(docs.current_page).to eq(1)
155
+ expect(docs.next_page).to eq(nil)
156
+ expect(docs.previous_page).to eq(nil)
155
157
  end
156
158
 
157
159
  it "provides custom properties for pagination" do
@@ -160,20 +162,22 @@ RSpec.describe "Search" do
160
162
  Elasticity::Search::Definition.new(
161
163
  index_name,
162
164
  document_type,
163
- { size: 14, from: 25, filter: {} }
165
+ { size: 15, from: 15, filter: {} }
164
166
  )
165
167
  )
166
168
  expect(client).to receive(:search).
167
169
  with(
168
170
  index: index_name,
169
171
  type: document_type,
170
- body: { size: 14, from: 25, filter: {} }
172
+ body: { size: 15, from: 15, filter: {} }
171
173
  ).and_return({ "hits" => { "total" => 112, "hits" => [] } })
172
174
  docs = subject.documents(mapper)
173
175
 
174
- expect(docs.per_page).to eq(14)
176
+ expect(docs.per_page).to eq(15)
175
177
  expect(docs.total_pages).to eq(8)
176
178
  expect(docs.current_page).to eq(2)
179
+ expect(docs.next_page).to eq(3)
180
+ expect(docs.previous_page).to eq(1)
177
181
  end
178
182
  end
179
183
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: es-elasticity
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.6.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rodrigo Kochenburger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-26 00:00:00.000000000 Z
11
+ date: 2016-07-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -230,7 +230,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
230
230
  version: '0'
231
231
  requirements: []
232
232
  rubyforge_project:
233
- rubygems_version: 2.4.5
233
+ rubygems_version: 2.4.5.1
234
234
  signing_key:
235
235
  specification_version: 4
236
236
  summary: ActiveModel-based library for working with Elasticsearch