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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4389b2a1e238f60babf42360ca0516ce80a44c08
4
- data.tar.gz: 28812f1413d6fbf0a77fa146b6292d59c9cd75fb
3
+ metadata.gz: 3489925baf41679f2a9aa16aae290404e741354f
4
+ data.tar.gz: 21b226a58a8b355bb1436384760d1c99272ce6d5
5
5
  SHA512:
6
- metadata.gz: cdb2822452dad56ea492abcf1a248b766cc81b64b34e5789bd762b502c86076bebf227709385d5be8c660760e481f76e79b4e0f9f980b2d49b08d3e9c9ca82bf
7
- data.tar.gz: bbec41df09fc57dc948f85dcde4776c17c158f8a4a9f34c1bebc091674c80d95702ad851ec4c1dd8975895e9c6f2d67d0e61101dc92d1e080fbfea463ae360a4
6
+ metadata.gz: 37358c84deea5643769466d6a6c63a05483b88aecaa5367b3dcfa62bec387c2a0250155329978a641ab2f8e4fb0afacfd26e033206a60527f1afbc5ff02e2600
7
+ data.tar.gz: e29b7000e79e4cb3dc1052d4aec1d3f7bec4ceec8f3704ecbc0da4baaefbabaf3b1736968ab7328dba88f3444bcc9a6f5311970c649ac094fd320bac6e7cc69a
@@ -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: result[HITS][TOTAL] || 0,
344
- results: block_given? ? (records.map {|record| yield record}).compact : records
353
+ total: total,
354
+ results: results
345
355
  }
346
356
  end
347
357
 
@@ -1,3 +1,3 @@
1
1
  module CoElasticQuery
2
- VERSION = "3.0.1"
2
+ VERSION = "3.0.2"
3
3
  end
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.1
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-03-04 00:00:00.000000000 Z
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.10
106
+ rubygems_version: 2.6.12
107
107
  signing_key:
108
108
  specification_version: 4
109
109
  summary: Elasticsearch query generator