Class: SearchController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- SearchController
- Defined in:
- app/controllers/search_controller.rb
Class Method Summary collapse
- .index_tank ⇒ Object
-
.search(query) ⇒ Object
retrieve docs from IndexTank.
Instance Method Summary collapse
Methods inherited from ApplicationController
Class Method Details
.index_tank ⇒ Object
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
#index ⇒ Object
23 24 25 |
# File 'app/controllers/search_controller.rb', line 23 def index @docs = SearchController.search(params[:query]) if params[:query].present? end |