es-elasticity 0.6.2 → 0.6.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 +4 -4
- data/README.md +1 -1
- data/lib/elasticity/search.rb +19 -9
- data/lib/elasticity/version.rb +1 -1
- data/spec/units/search_spec.rb +7 -3
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db223045f4a1f6c4550940c3a6a8ab31313e2641
|
4
|
+
data.tar.gz: 05c9d8c099afe031a5c603c0cd4ab54e1b8d6fb7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
]
|
data/lib/elasticity/search.rb
CHANGED
@@ -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, :
|
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
|
-
|
312
|
-
|
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
|
data/lib/elasticity/version.rb
CHANGED
data/spec/units/search_spec.rb
CHANGED
@@ -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:
|
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:
|
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(
|
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.
|
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-
|
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
|