Class: SearchController

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

Instance Method Summary collapse

Instance Method Details

#indexObject



2
3
4
5
6
# File 'app/controllers/search_controller.rb', line 2

def index
  q = params[:term]
  @searcher = Searcher.search query: q
  render layout: false
end

#mentionsObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/controllers/search_controller.rb', line 8

def mentions
  q = params[:query]
  delimiter = params[:delimiter]

  search_group = "pages,attachments"
  if delimiter == "!"
    search_group = "attachments"
  end

  q = ["title:#{q}", "filename:#{q}", "name:#{q}", "email:#{q}"].join(" OR ")
  @searcher = Searcher.search q: q, search_group: search_group

  results = []
  @searcher.results_with_hits{|result, hit| results << process_result(result, hit) }
  render json: results
end