co-elastic-query 3.0.1 → 3.0.2
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/lib/co-elastic-query.rb +12 -2
- data/lib/co-elastic-query/version.rb +1 -1
- 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: 3489925baf41679f2a9aa16aae290404e741354f
|
4
|
+
data.tar.gz: 21b226a58a8b355bb1436384760d1c99272ce6d5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 37358c84deea5643769466d6a6c63a05483b88aecaa5367b3dcfa62bec387c2a0250155329978a641ab2f8e4fb0afacfd26e033206a60527f1afbc5ff02e2600
|
7
|
+
data.tar.gz: e29b7000e79e4cb3dc1052d4aec1d3f7bec4ceec8f3704ecbc0da4baaefbabaf3b1736968ab7328dba88f3444bcc9a6f5311970c649ac094fd320bac6e7cc69a
|
data/lib/co-elastic-query.rb
CHANGED
@@ -339,9 +339,19 @@ class Elastic
|
|
339
339
|
# from the list.
|
340
340
|
result = Elastic.search(query)
|
341
341
|
records = Array(@klass.find_by_id(result[HITS][HITS].map {|entry| entry[ID]}))
|
342
|
+
results = block_given? ? (records.map {|record| yield record}).compact : records
|
343
|
+
|
344
|
+
# Ensure the total is accurate
|
345
|
+
total = result[HITS][TOTAL] || 0
|
346
|
+
total = total - (records.length - results.length) # adjust for compaction
|
347
|
+
|
348
|
+
# We check records against limit (pre-compaction) and total against actual result length
|
349
|
+
# Worst case senario is there is one additional request for results at an offset that returns no results.
|
350
|
+
# The total results number will be accurate on the final page of results from the clients perspective.
|
351
|
+
total = results.length + builder.offset if records.length < builder.limit && total > (results.length + builder.offset)
|
342
352
|
{
|
343
|
-
total:
|
344
|
-
results:
|
353
|
+
total: total,
|
354
|
+
results: results
|
345
355
|
}
|
346
356
|
end
|
347
357
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: co-elastic-query
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stephen von Takach
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-
|
12
|
+
date: 2017-08-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -103,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
103
103
|
version: '0'
|
104
104
|
requirements: []
|
105
105
|
rubyforge_project:
|
106
|
-
rubygems_version: 2.6.
|
106
|
+
rubygems_version: 2.6.12
|
107
107
|
signing_key:
|
108
108
|
specification_version: 4
|
109
109
|
summary: Elasticsearch query generator
|