Class: SearchController

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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationController

#robot?

Class Method Details

.index_tankObject



7
8
9
10
11
# File 'app/controllers/search_controller.rb', line 7

def self.index_tank
  @api = IndexTank::Client.new(ENV['WHITEBOARD_SEARCHIFY_API_URL'] || 'http://your_api_url')
  @index ||= @api.indexes(ENV['WHITEBOARD_SEARCHIFY_INDEX'] || 'cmux')
  @index
end

.search(query) ⇒ Object

retrieve docs from IndexTank



14
15
16
17
18
19
20
21
# File 'app/controllers/search_controller.rb', line 14

def self.search(query)
  query = query.gsub(/\W+/, ' ').strip

  if query.present?
    query << "*"
    index_tank.search("#{query} OR title:#{query}", :fetch => 'timestamp,url,text,title', :snippet => 'text')
  end
end

Instance Method Details

#indexObject



23
24
25
# File 'app/controllers/search_controller.rb', line 23

def index
  @docs = SearchController.search(params[:query]) if params[:query].present?
end