search-engine-for-typesense 30.1.8.10 → 30.1.8.11

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
  SHA256:
3
- metadata.gz: 384ef1b163431fc5ed44e94b039ed6c63475d03eac7beb021895f3707c2ed68b
4
- data.tar.gz: 8a138c55d4de91d43d4d99ccff25c3b0be6c514660b5afd8d94d04384e7a815a
3
+ metadata.gz: 95396b4ac85d2dfc142b05cf38aea45e73fd551ec7acb6915da3d7df7ffde9dd
4
+ data.tar.gz: 644a13a4a7ec1c8a841b19b6e8b59b88762b36db235428c13b5483a1082996c4
5
5
  SHA512:
6
- metadata.gz: af0f76bc2e13c1a14685a5cd9f50efa6a1493c57a697c14534a053668549393906f2ad22b87e2efe27ccf7c1b45cf7b8d0bf2d7298280bddad53048239618ce6
7
- data.tar.gz: abafcd224584bb4ac206de5e95959c3a22102560f97bd6d3ea6122045377e2b0e3c397a699a813ec83d428df1d80003b8eb490581af98e01b8090067f78e08cb
6
+ metadata.gz: a59fc89cefc6c5a320616737159e6adbeebad8dac16886dea3b9d4e25e8124028469fc62b30c1f45bf53c1e6c2addad54aee694c40bfbe14cc399a93a9732625
7
+ data.tar.gz: eaa3305204a97489af5bf1d2e89062f0be63c922425061c9705b05cb44f16035dd8bc1eac7740fc8146c8a0ad38ecdeec2a3a3af564cec39188371828988d302
@@ -294,6 +294,8 @@ module SearchEngine
294
294
  end
295
295
 
296
296
  def exists?(relation)
297
+ return count(relation).positive? if relation.send(:curation_filter_curated_hits?)
298
+
297
299
  loaded = relation.instance_variable_get(:@__loaded)
298
300
  memo = relation.instance_variable_get(:@__result_memo)
299
301
  return memo.found.to_i.positive? if loaded && memo
@@ -303,8 +305,8 @@ module SearchEngine
303
305
 
304
306
  def count(relation)
305
307
  if relation.send(:curation_filter_curated_hits?)
306
- to_a(relation)
307
- return relation.send(:curated_indices_for_current_result).size
308
+ result = execute(relation)
309
+ return curated_total_count(result)
308
310
  end
309
311
 
310
312
  loaded = relation.instance_variable_get(:@__loaded)
@@ -364,6 +366,21 @@ module SearchEngine
364
366
  end
365
367
  module_function :fetch_found_only
366
368
 
369
+ def curated_total_count(result)
370
+ raw = result.raw || {}
371
+ base_count = raw['found_docs'] || raw[:found_docs] || result.found
372
+
373
+ base_count.to_i + curated_hits_count(result)
374
+ end
375
+ module_function :curated_total_count
376
+
377
+ def curated_hits_count(result)
378
+ result.to_a.count do |obj|
379
+ obj.respond_to?(:curated_hit?) && obj.curated_hit?
380
+ end
381
+ end
382
+ module_function :curated_hits_count
383
+
367
384
  # Detect Typesense 400 errors caused by missing infix/prefix configuration
368
385
  # e.g., "Could not find `name` in the infix index. Make sure to enable infix search by specifying `infix: true` in the schema."
369
386
  def infix_missing_error?(error)
@@ -563,12 +563,6 @@ module SearchEngine
563
563
 
564
564
  # pluck helpers reside in Materializers
565
565
 
566
- def curated_indices_for_current_result
567
- @__result_memo.to_a.each_with_index.select do |obj, _idx|
568
- obj.respond_to?(:curated_hit?) && obj.curated_hit?
569
- end.map(&:last)
570
- end
571
-
572
566
  def curation_filter_curated_hits?
573
567
  @state[:curation] && @state[:curation][:filter_curated_hits]
574
568
  end
@@ -3,5 +3,5 @@
3
3
  module SearchEngine
4
4
  # Current gem version.
5
5
  # @return [String]
6
- VERSION = '30.1.8.10'
6
+ VERSION = '30.1.8.11'
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: search-engine-for-typesense
3
3
  version: !ruby/object:Gem::Version
4
- version: 30.1.8.10
4
+ version: 30.1.8.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nikita Shkoda