Class: Elasticfusion::Search::Wrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/elasticfusion/search/wrapper.rb

Instance Method Summary collapse

Constructor Details

#initialize(model, query, &block) ⇒ Wrapper

Returns a new instance of Wrapper.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/elasticfusion/search/wrapper.rb', line 14

def initialize(model, query, &block)
  @search_runner      = model.method(:search)

  @searchable_mapping = model.elasticfusion[:searchable_mapping]
  @searchable_fields  = model.elasticfusion[:searchable_fields]
  @keyword_field      = model.elasticfusion[:keyword_field]

  @builder = Search::Builder.new(model.elasticfusion)
  @builder.instance_eval(&block) if block_given?

  # The subset of queries that is currently supported can be executed
  # in the filter context, which does not compute _score and can be cached.
  # It cannot be used for relevance sorting, though.
  @builder.filter parse_query(query) if query.present?
end

Instance Method Details

#elasticsearch_requestObject



36
37
38
39
40
# File 'lib/elasticfusion/search/wrapper.rb', line 36

def elasticsearch_request
  { query: { bool: { must: @builder.queries,
                     filter: @builder.filters } },
    sort: @builder.sorts }
end

#peekerObject



42
43
44
# File 'lib/elasticfusion/search/wrapper.rb', line 42

def peeker
  Peeker.new(self)
end

#perform(request = elasticsearch_request) ⇒ Object



32
33
34
# File 'lib/elasticfusion/search/wrapper.rb', line 32

def perform(request = elasticsearch_request)
  @search_runner.call(request)
end