Class: SearchController

Inherits:
ApplicationController
  • Object
show all
Includes:
ActionView::Helpers::SanitizeHelper
Defined in:
app/controllers/search_controller.rb

Constant Summary collapse

RESULTS_SEARCH_PER_PAGE =
16

Instance Method Summary collapse

Instance Method Details

#indexObject



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
39
40
41
42
43
# File 'app/controllers/search_controller.rb', line 6

def index
  @search_result =
    if params[:q].blank? || params[:q].strip.size < SocialStream::Search::MIN_QUERY
      Kaminari.paginate_array([])
    elsif params[:mode] == "quick"
      search :quick
    else
      search :extended
    end

  respond_to do |format|
    format.html {
      if request.xhr?
        if params[:mode] == "quick"
          render partial: "quick"
        else
          if params[:q].present?
            render partial: 'results'
          else
            render partial: 'index'
          end
        end
      end
    }

    format.json {
      json_obj = (
        params[:type].present? ?
        { params[:type].pluralize => @search_result } :
        @search_result
      )

      render :json => json_obj.as_json(helper: self)
    }

    format.js
  end
end