Module: Caoutsearch::Search::BatchMethods
- Included in:
- Base
- Defined in:
- lib/caoutsearch/search/batch_methods.rb
Instance Method Summary collapse
- #find_each_hit(**options, &block) ⇒ Object
- #find_each_record(**options, &block) ⇒ Object
- #find_hits_in_batches(implementation: :search_after, **options) ⇒ Object
- #find_records_in_batches(**options) ⇒ Object
- #scroll_records(**options) ⇒ Object
- #scroll_records_in_batches(**options) ⇒ Object
Instance Method Details
#find_each_hit(**options, &block) ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/caoutsearch/search/batch_methods.rb', line 6 def find_each_hit(**, &block) return to_enum(:find_each_hit, **) { total_count } unless block find_hits_in_batches(**) do |hits| hits.each(&block) end end |
#find_each_record(**options, &block) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/caoutsearch/search/batch_methods.rb', line 14 def find_each_record(**, &block) return to_enum(:find_each_record, **) { total_count } unless block find_records_in_batches(**) do |relation| relation.each(&block) end end |
#find_hits_in_batches(implementation: :search_after, **options) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/caoutsearch/search/batch_methods.rb', line 34 def find_hits_in_batches(implementation: :search_after, **) batch_size = [:batch_size]&.to_i || @current_limit&.to_i || 1000 unless block_given? return to_enum(:find_hits_in_batches, **) do total_count.div(batch_size) + 1 end end unless %i[search_after scroll].include?(implementation) raise ArgumentError, "unexpected implementation argument: #{implementation.inspect}" end method(implementation).call(batch_size: batch_size, **) do |hits| yield hits end end |
#find_records_in_batches(**options) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/caoutsearch/search/batch_methods.rb', line 22 def find_records_in_batches(**) unless block_given? return to_enum(:find_records_in_batches, **) do find_hits_in_batches(**).size end end find_hits_in_batches(**) do |hits| yield records_adapter.call(model, hits, skip_query_cache: true) end end |
#scroll_records(**options) ⇒ Object
57 58 59 60 |
# File 'lib/caoutsearch/search/batch_methods.rb', line 57 def scroll_records(**) ActiveSupport::Deprecation.warn("scroll_records is deprecated, use find_each_record instead") find_each_record(implementation: :scroll, **) end |
#scroll_records_in_batches(**options) ⇒ Object
52 53 54 55 |
# File 'lib/caoutsearch/search/batch_methods.rb', line 52 def scroll_records_in_batches(**) ActiveSupport::Deprecation.warn("scroll_records_in_batches is deprecated, use find_records_in_batches instead") find_records_in_batches(implementation: :scroll, **) end |