Class: Elasticated::Repository::NormalSearch
- Defined in:
- lib/elasticated/repository/normal_search.rb
Instance Attribute Summary
Attributes inherited from Search
#aggregated, #opts, #query, #repository
Instance Method Summary collapse
Methods inherited from Search
Constructor Details
This class inherits a constructor from Elasticated::Repository::Search
Instance Method Details
#execute ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/elasticated/repository/normal_search.rb', line 5 def execute body = aggregated ? query.build_for_aggregated_search : query.build_for_search initial_offset = offset = query._from # TODO do it nicer size = repository.search_page_size override! body, size, offset response = client.search body, opts results = parse_and_prepare_results response, query target_size = query.limited? ? query._size : (results.hits.total - offset) total_pages = (target_size / size.to_f).ceil current_page = 1 body = query.build_for_search loop do break if current_page >= total_pages offset = initial_offset + size * current_page size = target_size - offset + initial_offset if query.limited? && offset - initial_offset + size > target_size override! body, size, offset response = client.search body, opts new_results = parse_and_prepare_results response results.append new_results break if new_results.count < size current_page += 1 end results end |