Module: RocketCMS::Controllers::Search

Extended by:
ActiveSupport::Concern
Included in:
SearchController
Defined in:
lib/rocket_cms/controllers/search.rb

Instance Method Summary collapse

Instance Method Details

#indexObject



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
37
38
# File 'lib/rocket_cms/controllers/search.rb', line 5

def index
  if params[:query].blank?
    @results = []
  else
    if RocketCMS.mongoid?
      @results = Mongoid::Elasticsearch.search({
        body: {
          query: {
            query_string: {
              query: Mongoid::Elasticsearch::Utils.clean(params[:query])
            }
          },
          highlight: {
            require_field_match: false,
            fields: {
              name: {
                number_of_fragments: 1,
                size_of_fragments: 120
              },
              content: {
                number_of_fragments: 1,
                size_of_fragments: 220
              }
            }
          }
        }},
        page: params[:page],
        per_page: RocketCMS.config.search_per_page,
      )
    else
      @results = PgSearch.multisearch(params[:query]).page(params[:page]).per(RocketCMS.config.search_per_page)
    end
  end
end