Class: Elasticfusion::Search::Peeker
- Inherits:
-
Object
- Object
- Elasticfusion::Search::Peeker
- Defined in:
- lib/elasticfusion/search/peeker.rb
Overview
An instance of Peeker
can return consecutive (previous and next) records for a given record and an instance of Search::Wrapper
.
Under the hood, it uses search_after parameters (see www.elastic.co/guide/en/elasticsearch/reference/5.2/search-request-search-after.html).
Instance Method Summary collapse
-
#initialize(wrapper) ⇒ Peeker
constructor
A new instance of Peeker.
- #next_record(current_record) ⇒ Object
- #previous_record(current_record) ⇒ Object
Constructor Details
#initialize(wrapper) ⇒ Peeker
Returns a new instance of Peeker.
11 12 13 |
# File 'lib/elasticfusion/search/peeker.rb', line 11 def initialize(wrapper) @wrapper = wrapper end |
Instance Method Details
#next_record(current_record) ⇒ Object
15 16 17 18 19 |
# File 'lib/elasticfusion/search/peeker.rb', line 15 def next_record(current_record) request = @wrapper.elasticsearch_request first_record_after(current_record, request) end |
#previous_record(current_record) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/elasticfusion/search/peeker.rb', line 21 def previous_record(current_record) request = @wrapper.elasticsearch_request request[:sort] = reverse_sort request[:sort] first_record_after(current_record, request) end |