Class: SearchController

Inherits:
ApplicationController show all
Defined in:
app/controllers/search_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#fresh_when, #redirect_back_or_default, #redirect_referrer_or_default, #render_403, #render_404, #render_optional_error_file, #require_user, #set_active_menu, #set_locale, #set_seo_meta, #store_location, #unread_notify_count

Instance Method Details

#indexObject


2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/controllers/search_controller.rb', line 2

def index
  search_params = {
    query: {
      simple_query_string: {
        query: params[:q],
        default_operator: 'AND',
        minimum_should_match: '70%',
        fields: ['title', 'body', 'name', 'login']
      }
    },
    highlight: {
      pre_tags: ["[h]"],
      post_tags: ["[/h]"],
      fields: { title: {}, body: {}, name: {}, login: {} }
    }
  }
  @result = Elasticsearch::Model.search(search_params, [Topic, User, Page]).paginate(page: params[:page], per_page: 30)
end