Class: Elasticated::Repository::ResumableSearch

Inherits:
Search
  • Object
show all
Defined in:
lib/elasticated/repository/resumable_search.rb

Instance Attribute Summary collapse

Attributes inherited from Search

#aggregated, #opts, #query, #repository

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Search

#initialize

Constructor Details

This class inherits a constructor from Elasticated::Repository::Search

Instance Attribute Details

#completedObject

Returns the value of attribute completed.



11
12
13
# File 'lib/elasticated/repository/resumable_search.rb', line 11

def completed
  @completed
end

#scroll_idObject

Returns the value of attribute scroll_id.



11
12
13
# File 'lib/elasticated/repository/resumable_search.rb', line 11

def scroll_id
  @scroll_id
end

Class Method Details

.from_scroll_id(repository, scroll_id) ⇒ Object



5
6
7
8
9
# File 'lib/elasticated/repository/resumable_search.rb', line 5

def self.from_scroll_id(repository, scroll_id)
  search = new repository, nil
  search.scroll_id = scroll_id
  search
end

Instance Method Details

#completed?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/elasticated/repository/resumable_search.rb', line 40

def completed?
  !!completed
end

#executeObject



44
45
46
47
48
# File 'lib/elasticated/repository/resumable_search.rb', line 44

def execute
  results = start
  results.append fetch while !completed?
  results
end

#fetchObject



30
31
32
33
34
35
36
37
38
# File 'lib/elasticated/repository/resumable_search.rb', line 30

def fetch
  raise "No scroll_id present" unless scroll_id
  raise "No more information to fetch: scroll completed" if completed?
  response = client.scroll scroll_id, scroll: scroll_expiration_time
  results = parse_and_prepare_results response
  self.scroll_id = results.scroll_id
  mark_completed! if results.documents.empty?
  results
end

#startObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/elasticated/repository/resumable_search.rb', line 13

def start
  # aggregations
  aggregation_results = if aggregated
    body = query.build_for_aggregations
    response = client.search body, opts
    parse_and_prepare_results response, query
  end
  # search
  body = query.build_for_search
  response = client.search body, opts.merge(scroll: scroll_expiration_time, size: scroll_page_size)
  results = parse_and_prepare_results response
  results.append aggregation_results if aggregation_results
  self.scroll_id = results.scroll_id
  mark_completed! if results.documents.count < scroll_page_size
  results
end