Class: HasHelpers::Search::Elasticsearch

Inherits:
Object
  • Object
show all
Includes:
ElasticsearchShared, Provider, SearchExtensions::ProviderExtensions
Defined in:
app/lib/has_helpers/search/elasticsearch.rb

Constant Summary

Constants included from Provider

Provider::PAGINATION_ATTRS

Instance Attribute Summary

Attributes included from Provider

#controller

Instance Method Summary collapse

Methods included from ElasticsearchShared

#class_from_resource, #owner_relation, #searchkick_results

Methods included from Provider

#initialize, owner_relation_from_scope, #results, #search_options, #search_prefix, #search_screen

Instance Method Details

#exec_query(resource, query, options) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/lib/has_helpers/search/elasticsearch.rb', line 14

def exec_query(resource, query, options)
  results = searchkick_results(resource, query, query_options(resource, query, options))
  new_results = results[:results]
  new_results = new_results.paginate(page: 1, per_page: 15)

  self.class::PAGINATION_ATTRS.each do |attr|
    # set the instance variables for will_paginate
    #   { results: [...], current_page: 1, per_page: 15, total_entries: 42 }
    new_results.instance_variable_set("@#{ attr }", results[attr])
  end

  new_results
end

#query_options(resource, query, options) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/lib/has_helpers/search/elasticsearch.rb', line 28

def query_options(resource, query, options)
  if ::HasHelpers::SearchAPI.options_hook.respond_to?(:to_proc)
    ::HasHelpers::SearchAPI.options_hook.call(
      resources: Array(resource),
      query: query,
      options: options,
      current_user: current_user,
      provider: ::HasHelpers::Query::Elasticsearch
    )
  else
    options
  end
end

#sanitize_query(query) ⇒ Object



10
11
12
# File 'app/lib/has_helpers/search/elasticsearch.rb', line 10

def sanitize_query(query)
  query
end